{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其实Numpy之类的单讲特别没意思，但不稍微说下后面说实际应用又不行，所以大家就练练手吧\n",
    "\n",
    "代码裤子： <a href=\"https://github.com/lotapp/BaseCode\" target=\"_blank\">https://github.com/lotapp/BaseCode</a>\n",
    "\n",
    "在线编程： <a href=\"https://mybinder.org/v2/gh/lotapp/BaseCode/master\" target=\"_blank\">https://mybinder.org/v2/gh/lotapp/BaseCode/master</a>\n",
    "\n",
    "在线地址：<a href=\"http://github.lesschina.com/python/ai/numpy\" target=\"_blank\">https://www.cnblogs.com/dotnetcrazy/p/9309555.html</a>\n",
    "\n",
    "## 1.数组定义、常见属性\n",
    "\n",
    "引入一下`Numpy`模块，`Numpy`的数组使用可以查看一下帮助文档，`Numpy`的`array`数组类型必须是一致的（后面会讲）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入Numpy模块\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function array in module numpy.core.multiarray:\n",
      "\n",
      "array(...)\n",
      "    array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)\n",
      "    \n",
      "    Create an array.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    object : array_like\n",
      "        An array, any object exposing the array interface, an object whose\n",
      "        __array__ method returns an array, or any (nested) sequence.\n",
      "    dtype : data-type, optional\n",
      "        The desired data-type for the array.  If not given, then the type will\n",
      "        be determined as the minimum type required to hold the objects in the\n",
      "        sequence.  This argument can only be used to 'upcast' the array.  For\n",
      "        downcasting, use the .astype(t) method.\n",
      "    copy : bool, optional\n",
      "        If true (default), then the object is copied.  Otherwise, a copy will\n",
      "        only be made if __array__ returns a copy, if obj is a nested sequence,\n",
      "        or if a copy is needed to satisfy any of the other requirements\n",
      "        (`dtype`, `order`, etc.).\n",
      "    order : {'K', 'A', 'C', 'F'}, optional\n",
      "        Specify the memory layout of the array. If object is not an array, the\n",
      "        newly created array will be in C order (row major) unless 'F' is\n",
      "        specified, in which case it will be in Fortran order (column major).\n",
      "        If object is an array the following holds.\n",
      "    \n",
      "        ===== ========= ===================================================\n",
      "        order  no copy                     copy=True\n",
      "        ===== ========= ===================================================\n",
      "        'K'   unchanged F & C order preserved, otherwise most similar order\n",
      "        'A'   unchanged F order if input is F and not C, otherwise C order\n",
      "        'C'   C order   C order\n",
      "        'F'   F order   F order\n",
      "        ===== ========= ===================================================\n",
      "    \n",
      "        When ``copy=False`` and a copy is made for other reasons, the result is\n",
      "        the same as if ``copy=True``, with some exceptions for `A`, see the\n",
      "        Notes section. The default order is 'K'.\n",
      "    subok : bool, optional\n",
      "        If True, then sub-classes will be passed-through, otherwise\n",
      "        the returned array will be forced to be a base-class array (default).\n",
      "    ndmin : int, optional\n",
      "        Specifies the minimum number of dimensions that the resulting\n",
      "        array should have.  Ones will be pre-pended to the shape as\n",
      "        needed to meet this requirement.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : ndarray\n",
      "        An array object satisfying the specified requirements.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    empty, empty_like, zeros, zeros_like, ones, ones_like, full, full_like\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    When order is 'A' and `object` is an array in neither 'C' nor 'F' order,\n",
      "    and a copy is forced by a change in dtype, then the order of the result is\n",
      "    not necessarily 'C' as expected. This is likely a bug.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.array([1, 2, 3])\n",
      "    array([1, 2, 3])\n",
      "    \n",
      "    Upcasting:\n",
      "    \n",
      "    >>> np.array([1, 2, 3.0])\n",
      "    array([ 1.,  2.,  3.])\n",
      "    \n",
      "    More than one dimension:\n",
      "    \n",
      "    >>> np.array([[1, 2], [3, 4]])\n",
      "    array([[1, 2],\n",
      "           [3, 4]])\n",
      "    \n",
      "    Minimum dimensions 2:\n",
      "    \n",
      "    >>> np.array([1, 2, 3], ndmin=2)\n",
      "    array([[1, 2, 3]])\n",
      "    \n",
      "    Type provided:\n",
      "    \n",
      "    >>> np.array([1, 2, 3], dtype=complex)\n",
      "    array([ 1.+0.j,  2.+0.j,  3.+0.j])\n",
      "    \n",
      "    Data-type consisting of more than one element:\n",
      "    \n",
      "    >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])\n",
      "    >>> x['a']\n",
      "    array([1, 3])\n",
      "    \n",
      "    Creating an array from sub-classes:\n",
      "    \n",
      "    >>> np.array(np.mat('1 2; 3 4'))\n",
      "    array([[1, 2],\n",
      "           [3, 4]])\n",
      "    \n",
      "    >>> np.array(np.mat('1 2; 3 4'), subok=True)\n",
      "    matrix([[1, 2],\n",
      "            [3, 4]])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.array) #或者用 np.array? 查看"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1.通过List创建数组\n",
    "\n",
    "`np.array(list)`\n",
    "\n",
    "**注意**：\n",
    "\n",
    "`print(np.array([1,2,3,4,5]))`和`np.array([1,2,3,4,5])`\n",
    "\n",
    "**在交互摸索下显示是稍微有点区别的**，千万别以为是不一样的东西\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造一个list1\n",
    "list1 = list(range(10))\n",
    "print(list1)\n",
    "\n",
    "# 通过List创建一个一维数组\n",
    "array1 = np.array(list1)\n",
    "\n",
    "print(array1)\n",
    "type(array1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 你直接写也一样\n",
    "test_array = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
    "\n",
    "print(test_array)\n",
    "type(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n",
      "[[0 1 2 3 4 5 6 7 8 9]\n",
      " [0 1 2 3 4 5 6 7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "# 创建一个嵌套列表\n",
    "list2 = [list1,list1]\n",
    "print(list2)\n",
    "\n",
    "# 通过嵌套列表创建二维数组\n",
    "array2 = np.array(list2)\n",
    "print(array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[1 2 3]\n",
      "  [4 5 6]\n",
      "  [7 8 9]]\n",
      "\n",
      " [[1 2 3]\n",
      "  [4 5 6]\n",
      "  [7 8 9]]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建3维数组\n",
    "array3 = np.array([\n",
    "    [[1,2,3],[4,5,6],[7,8,9]],\n",
    "    [[1,2,3],[4,5,6],[7,8,9]]\n",
    "])\n",
    "\n",
    "print(array3)\n",
    "type(array3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 扩展部分 ########################\n",
    "\n",
    "# 其实你通过元组创建也一样，只是官方演示文档里面用的是list\n",
    "\n",
    "# 逆天推荐使用列表（和官方文档一致嘛）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 一维数组\n",
    "np.array((1,2,3,4,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5]\n"
     ]
    }
   ],
   "source": [
    "# 都是一个数组，你print和直接输入名字是稍微有点区别的\n",
    "# 千万别以为是不一样东西\n",
    "\n",
    "print(np.array((1,2,3,4,5)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 二维数组\n",
    "np.array(((1,2,3),(4,5,6)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 二维数组，这种方式也一样\n",
    "np.array(([1,2,3],[4,5,6]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2.常用属性\n",
    "\n",
    "`ndim` 查看数组维度\n",
    "\n",
    "`shape` 查看数组形状\n",
    "\n",
    "`size` 查看数组含有多少元素（行*列）\n",
    "\n",
    "`dtype` 查看元素的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on ndarray object:\n",
      "\n",
      "class ndarray(builtins.object)\n",
      " |  ndarray(shape, dtype=float, buffer=None, offset=0,\n",
      " |          strides=None, order=None)\n",
      " |  \n",
      " |  An array object represents a multidimensional, homogeneous array\n",
      " |  of fixed-size items.  An associated data-type object describes the\n",
      " |  format of each element in the array (its byte-order, how many bytes it\n",
      " |  occupies in memory, whether it is an integer, a floating point number,\n",
      " |  or something else, etc.)\n",
      " |  \n",
      " |  Arrays should be constructed using `array`, `zeros` or `empty` (refer\n",
      " |  to the See Also section below).  The parameters given here refer to\n",
      " |  a low-level method (`ndarray(...)`) for instantiating an array.\n",
      " |  \n",
      " |  For more information, refer to the `numpy` module and examine the\n",
      " |  methods and attributes of an array.\n",
      " |  \n",
      " |  Parameters\n",
      " |  ----------\n",
      " |  (for the __new__ method; see Notes below)\n",
      " |  \n",
      " |  shape : tuple of ints\n",
      " |      Shape of created array.\n",
      " |  dtype : data-type, optional\n",
      " |      Any object that can be interpreted as a numpy data type.\n",
      " |  buffer : object exposing buffer interface, optional\n",
      " |      Used to fill the array with data.\n",
      " |  offset : int, optional\n",
      " |      Offset of array data in buffer.\n",
      " |  strides : tuple of ints, optional\n",
      " |      Strides of data in memory.\n",
      " |  order : {'C', 'F'}, optional\n",
      " |      Row-major (C-style) or column-major (Fortran-style) order.\n",
      " |  \n",
      " |  Attributes\n",
      " |  ----------\n",
      " |  T : ndarray\n",
      " |      Transpose of the array.\n",
      " |  data : buffer\n",
      " |      The array's elements, in memory.\n",
      " |  dtype : dtype object\n",
      " |      Describes the format of the elements in the array.\n",
      " |  flags : dict\n",
      " |      Dictionary containing information related to memory use, e.g.,\n",
      " |      'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc.\n",
      " |  flat : numpy.flatiter object\n",
      " |      Flattened version of the array as an iterator.  The iterator\n",
      " |      allows assignments, e.g., ``x.flat = 3`` (See `ndarray.flat` for\n",
      " |      assignment examples; TODO).\n",
      " |  imag : ndarray\n",
      " |      Imaginary part of the array.\n",
      " |  real : ndarray\n",
      " |      Real part of the array.\n",
      " |  size : int\n",
      " |      Number of elements in the array.\n",
      " |  itemsize : int\n",
      " |      The memory use of each array element in bytes.\n",
      " |  nbytes : int\n",
      " |      The total number of bytes required to store the array data,\n",
      " |      i.e., ``itemsize * size``.\n",
      " |  ndim : int\n",
      " |      The array's number of dimensions.\n",
      " |  shape : tuple of ints\n",
      " |      Shape of the array.\n",
      " |  strides : tuple of ints\n",
      " |      The step-size required to move from one element to the next in\n",
      " |      memory. For example, a contiguous ``(3, 4)`` array of type\n",
      " |      ``int16`` in C-order has strides ``(8, 2)``.  This implies that\n",
      " |      to move from element to element in memory requires jumps of 2 bytes.\n",
      " |      To move from row-to-row, one needs to jump 8 bytes at a time\n",
      " |      (``2 * 4``).\n",
      " |  ctypes : ctypes object\n",
      " |      Class containing properties of the array needed for interaction\n",
      " |      with ctypes.\n",
      " |  base : ndarray\n",
      " |      If the array is a view into another array, that array is its `base`\n",
      " |      (unless that array is also a view).  The `base` array is where the\n",
      " |      array data is actually stored.\n",
      " |  \n",
      " |  See Also\n",
      " |  --------\n",
      " |  array : Construct an array.\n",
      " |  zeros : Create an array, each element of which is zero.\n",
      " |  empty : Create an array, but leave its allocated memory unchanged (i.e.,\n",
      " |          it contains \"garbage\").\n",
      " |  dtype : Create a data-type.\n",
      " |  \n",
      " |  Notes\n",
      " |  -----\n",
      " |  There are two modes of creating an array using ``__new__``:\n",
      " |  \n",
      " |  1. If `buffer` is None, then only `shape`, `dtype`, and `order`\n",
      " |     are used.\n",
      " |  2. If `buffer` is an object exposing the buffer interface, then\n",
      " |     all keywords are interpreted.\n",
      " |  \n",
      " |  No ``__init__`` method is needed because the array is fully initialized\n",
      " |  after the ``__new__`` method.\n",
      " |  \n",
      " |  Examples\n",
      " |  --------\n",
      " |  These examples illustrate the low-level `ndarray` constructor.  Refer\n",
      " |  to the `See Also` section above for easier ways of constructing an\n",
      " |  ndarray.\n",
      " |  \n",
      " |  First mode, `buffer` is None:\n",
      " |  \n",
      " |  >>> np.ndarray(shape=(2,2), dtype=float, order='F')\n",
      " |  array([[ -1.13698227e+002,   4.25087011e-303],\n",
      " |         [  2.88528414e-306,   3.27025015e-309]])         #random\n",
      " |  \n",
      " |  Second mode:\n",
      " |  \n",
      " |  >>> np.ndarray((2,), buffer=np.array([1,2,3]),\n",
      " |  ...            offset=np.int_().itemsize,\n",
      " |  ...            dtype=int) # offset = 1*itemsize, i.e. skip first element\n",
      " |  array([2, 3])\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __abs__(self, /)\n",
      " |      abs(self)\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __and__(self, value, /)\n",
      " |      Return self&value.\n",
      " |  \n",
      " |  __array__(...)\n",
      " |      a.__array__(|dtype) -> reference if type unchanged, copy otherwise.\n",
      " |      \n",
      " |      Returns either a new reference to self if dtype is not given or a new array\n",
      " |      of provided data type if dtype is different from the current dtype of the\n",
      " |      array.\n",
      " |  \n",
      " |  __array_prepare__(...)\n",
      " |      a.__array_prepare__(obj) -> Object of same type as ndarray object obj.\n",
      " |  \n",
      " |  __array_ufunc__(...)\n",
      " |  \n",
      " |  __array_wrap__(...)\n",
      " |      a.__array_wrap__(obj) -> Object of same type as ndarray object a.\n",
      " |  \n",
      " |  __bool__(self, /)\n",
      " |      self != 0\n",
      " |  \n",
      " |  __complex__(...)\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __copy__(...)\n",
      " |      a.__copy__()\n",
      " |      \n",
      " |      Used if :func:`copy.copy` is called on an array. Returns a copy of the array.\n",
      " |      \n",
      " |      Equivalent to ``a.copy(order='K')``.\n",
      " |  \n",
      " |  __deepcopy__(...)\n",
      " |      a.__deepcopy__(memo, /) -> Deep copy of array.\n",
      " |      \n",
      " |      Used if :func:`copy.deepcopy` is called on an array.\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __divmod__(self, value, /)\n",
      " |      Return divmod(self, value).\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __float__(self, /)\n",
      " |      float(self)\n",
      " |  \n",
      " |  __floordiv__(self, value, /)\n",
      " |      Return self//value.\n",
      " |  \n",
      " |  __format__(...)\n",
      " |      default object formatter\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __iadd__(self, value, /)\n",
      " |      Return self+=value.\n",
      " |  \n",
      " |  __iand__(self, value, /)\n",
      " |      Return self&=value.\n",
      " |  \n",
      " |  __ifloordiv__(self, value, /)\n",
      " |      Return self//=value.\n",
      " |  \n",
      " |  __ilshift__(self, value, /)\n",
      " |      Return self<<=value.\n",
      " |  \n",
      " |  __imatmul__(self, value, /)\n",
      " |      Return self@=value.\n",
      " |  \n",
      " |  __imod__(self, value, /)\n",
      " |      Return self%=value.\n",
      " |  \n",
      " |  __imul__(self, value, /)\n",
      " |      Return self*=value.\n",
      " |  \n",
      " |  __index__(self, /)\n",
      " |      Return self converted to an integer, if self is suitable for use as an index into a list.\n",
      " |  \n",
      " |  __int__(self, /)\n",
      " |      int(self)\n",
      " |  \n",
      " |  __invert__(self, /)\n",
      " |      ~self\n",
      " |  \n",
      " |  __ior__(self, value, /)\n",
      " |      Return self|=value.\n",
      " |  \n",
      " |  __ipow__(self, value, /)\n",
      " |      Return self**=value.\n",
      " |  \n",
      " |  __irshift__(self, value, /)\n",
      " |      Return self>>=value.\n",
      " |  \n",
      " |  __isub__(self, value, /)\n",
      " |      Return self-=value.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __itruediv__(self, value, /)\n",
      " |      Return self/=value.\n",
      " |  \n",
      " |  __ixor__(self, value, /)\n",
      " |      Return self^=value.\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lshift__(self, value, /)\n",
      " |      Return self<<value.\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __matmul__(self, value, /)\n",
      " |      Return self@value.\n",
      " |  \n",
      " |  __mod__(self, value, /)\n",
      " |      Return self%value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __neg__(self, /)\n",
      " |      -self\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  __or__(self, value, /)\n",
      " |      Return self|value.\n",
      " |  \n",
      " |  __pos__(self, /)\n",
      " |      +self\n",
      " |  \n",
      " |  __pow__(self, value, mod=None, /)\n",
      " |      Return pow(self, value, mod).\n",
      " |  \n",
      " |  __radd__(self, value, /)\n",
      " |      Return value+self.\n",
      " |  \n",
      " |  __rand__(self, value, /)\n",
      " |      Return value&self.\n",
      " |  \n",
      " |  __rdivmod__(self, value, /)\n",
      " |      Return divmod(value, self).\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      a.__reduce__()\n",
      " |      \n",
      " |      For pickling.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __rfloordiv__(self, value, /)\n",
      " |      Return value//self.\n",
      " |  \n",
      " |  __rlshift__(self, value, /)\n",
      " |      Return value<<self.\n",
      " |  \n",
      " |  __rmatmul__(self, value, /)\n",
      " |      Return value@self.\n",
      " |  \n",
      " |  __rmod__(self, value, /)\n",
      " |      Return value%self.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __ror__(self, value, /)\n",
      " |      Return value|self.\n",
      " |  \n",
      " |  __rpow__(self, value, mod=None, /)\n",
      " |      Return pow(value, self, mod).\n",
      " |  \n",
      " |  __rrshift__(self, value, /)\n",
      " |      Return value>>self.\n",
      " |  \n",
      " |  __rshift__(self, value, /)\n",
      " |      Return self>>value.\n",
      " |  \n",
      " |  __rsub__(self, value, /)\n",
      " |      Return value-self.\n",
      " |  \n",
      " |  __rtruediv__(self, value, /)\n",
      " |      Return value/self.\n",
      " |  \n",
      " |  __rxor__(self, value, /)\n",
      " |      Return value^self.\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  __setstate__(...)\n",
      " |      a.__setstate__(state, /)\n",
      " |      \n",
      " |      For unpickling.\n",
      " |      \n",
      " |      The `state` argument must be a sequence that contains the following\n",
      " |      elements:\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      version : int\n",
      " |          optional pickle version. If omitted defaults to 0.\n",
      " |      shape : tuple\n",
      " |      dtype : data-type\n",
      " |      isFortran : bool\n",
      " |      rawdata : string or list\n",
      " |          a binary string with the data (or a list if 'a' is an object array)\n",
      " |  \n",
      " |  __sizeof__(...)\n",
      " |      __sizeof__() -> int\n",
      " |      size of object in memory, in bytes\n",
      " |  \n",
      " |  __str__(self, /)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  __sub__(self, value, /)\n",
      " |      Return self-value.\n",
      " |  \n",
      " |  __truediv__(self, value, /)\n",
      " |      Return self/value.\n",
      " |  \n",
      " |  __xor__(self, value, /)\n",
      " |      Return self^value.\n",
      " |  \n",
      " |  all(...)\n",
      " |      a.all(axis=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Returns True if all elements evaluate to True.\n",
      " |      \n",
      " |      Refer to `numpy.all` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.all : equivalent function\n",
      " |  \n",
      " |  any(...)\n",
      " |      a.any(axis=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Returns True if any of the elements of `a` evaluate to True.\n",
      " |      \n",
      " |      Refer to `numpy.any` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.any : equivalent function\n",
      " |  \n",
      " |  argmax(...)\n",
      " |      a.argmax(axis=None, out=None)\n",
      " |      \n",
      " |      Return indices of the maximum values along the given axis.\n",
      " |      \n",
      " |      Refer to `numpy.argmax` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.argmax : equivalent function\n",
      " |  \n",
      " |  argmin(...)\n",
      " |      a.argmin(axis=None, out=None)\n",
      " |      \n",
      " |      Return indices of the minimum values along the given axis of `a`.\n",
      " |      \n",
      " |      Refer to `numpy.argmin` for detailed documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.argmin : equivalent function\n",
      " |  \n",
      " |  argpartition(...)\n",
      " |      a.argpartition(kth, axis=-1, kind='introselect', order=None)\n",
      " |      \n",
      " |      Returns the indices that would partition this array.\n",
      " |      \n",
      " |      Refer to `numpy.argpartition` for full documentation.\n",
      " |      \n",
      " |      .. versionadded:: 1.8.0\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.argpartition : equivalent function\n",
      " |  \n",
      " |  argsort(...)\n",
      " |      a.argsort(axis=-1, kind='quicksort', order=None)\n",
      " |      \n",
      " |      Returns the indices that would sort this array.\n",
      " |      \n",
      " |      Refer to `numpy.argsort` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.argsort : equivalent function\n",
      " |  \n",
      " |  astype(...)\n",
      " |      a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True)\n",
      " |      \n",
      " |      Copy of the array, cast to a specified type.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      dtype : str or dtype\n",
      " |          Typecode or data-type to which the array is cast.\n",
      " |      order : {'C', 'F', 'A', 'K'}, optional\n",
      " |          Controls the memory layout order of the result.\n",
      " |          'C' means C order, 'F' means Fortran order, 'A'\n",
      " |          means 'F' order if all the arrays are Fortran contiguous,\n",
      " |          'C' order otherwise, and 'K' means as close to the\n",
      " |          order the array elements appear in memory as possible.\n",
      " |          Default is 'K'.\n",
      " |      casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional\n",
      " |          Controls what kind of data casting may occur. Defaults to 'unsafe'\n",
      " |          for backwards compatibility.\n",
      " |      \n",
      " |            * 'no' means the data types should not be cast at all.\n",
      " |            * 'equiv' means only byte-order changes are allowed.\n",
      " |            * 'safe' means only casts which can preserve values are allowed.\n",
      " |            * 'same_kind' means only safe casts or casts within a kind,\n",
      " |              like float64 to float32, are allowed.\n",
      " |            * 'unsafe' means any data conversions may be done.\n",
      " |      subok : bool, optional\n",
      " |          If True, then sub-classes will be passed-through (default), otherwise\n",
      " |          the returned array will be forced to be a base-class array.\n",
      " |      copy : bool, optional\n",
      " |          By default, astype always returns a newly allocated array. If this\n",
      " |          is set to false, and the `dtype`, `order`, and `subok`\n",
      " |          requirements are satisfied, the input array is returned instead\n",
      " |          of a copy.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      arr_t : ndarray\n",
      " |          Unless `copy` is False and the other conditions for returning the input\n",
      " |          array are satisfied (see description for `copy` input parameter), `arr_t`\n",
      " |          is a new array of the same shape as the input array, with dtype, order\n",
      " |          given by `dtype`, `order`.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Starting in NumPy 1.9, astype method now returns an error if the string\n",
      " |      dtype to cast to is not long enough in 'safe' casting mode to hold the max\n",
      " |      value of integer/float array that is being casted. Previously the casting\n",
      " |      was allowed even if the result was truncated.\n",
      " |      \n",
      " |      Raises\n",
      " |      ------\n",
      " |      ComplexWarning\n",
      " |          When casting from complex to float or int. To avoid this,\n",
      " |          one should use ``a.real.astype(t)``.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([1, 2, 2.5])\n",
      " |      >>> x\n",
      " |      array([ 1. ,  2. ,  2.5])\n",
      " |      \n",
      " |      >>> x.astype(int)\n",
      " |      array([1, 2, 2])\n",
      " |  \n",
      " |  byteswap(...)\n",
      " |      a.byteswap(inplace=False)\n",
      " |      \n",
      " |      Swap the bytes of the array elements\n",
      " |      \n",
      " |      Toggle between low-endian and big-endian data representation by\n",
      " |      returning a byteswapped array, optionally swapped in-place.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      inplace : bool, optional\n",
      " |          If ``True``, swap bytes in-place, default is ``False``.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      out : ndarray\n",
      " |          The byteswapped array. If `inplace` is ``True``, this is\n",
      " |          a view to self.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> A = np.array([1, 256, 8755], dtype=np.int16)\n",
      " |      >>> map(hex, A)\n",
      " |      ['0x1', '0x100', '0x2233']\n",
      " |      >>> A.byteswap(inplace=True)\n",
      " |      array([  256,     1, 13090], dtype=int16)\n",
      " |      >>> map(hex, A)\n",
      " |      ['0x100', '0x1', '0x3322']\n",
      " |      \n",
      " |      Arrays of strings are not swapped\n",
      " |      \n",
      " |      >>> A = np.array(['ceg', 'fac'])\n",
      " |      >>> A.byteswap()\n",
      " |      array(['ceg', 'fac'],\n",
      " |            dtype='|S3')\n",
      " |  \n",
      " |  choose(...)\n",
      " |      a.choose(choices, out=None, mode='raise')\n",
      " |      \n",
      " |      Use an index array to construct a new array from a set of choices.\n",
      " |      \n",
      " |      Refer to `numpy.choose` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.choose : equivalent function\n",
      " |  \n",
      " |  clip(...)\n",
      " |      a.clip(min=None, max=None, out=None)\n",
      " |      \n",
      " |      Return an array whose values are limited to ``[min, max]``.\n",
      " |      One of max or min must be given.\n",
      " |      \n",
      " |      Refer to `numpy.clip` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.clip : equivalent function\n",
      " |  \n",
      " |  compress(...)\n",
      " |      a.compress(condition, axis=None, out=None)\n",
      " |      \n",
      " |      Return selected slices of this array along given axis.\n",
      " |      \n",
      " |      Refer to `numpy.compress` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.compress : equivalent function\n",
      " |  \n",
      " |  conj(...)\n",
      " |      a.conj()\n",
      " |      \n",
      " |      Complex-conjugate all elements.\n",
      " |      \n",
      " |      Refer to `numpy.conjugate` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.conjugate : equivalent function\n",
      " |  \n",
      " |  conjugate(...)\n",
      " |      a.conjugate()\n",
      " |      \n",
      " |      Return the complex conjugate, element-wise.\n",
      " |      \n",
      " |      Refer to `numpy.conjugate` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.conjugate : equivalent function\n",
      " |  \n",
      " |  copy(...)\n",
      " |      a.copy(order='C')\n",
      " |      \n",
      " |      Return a copy of the array.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      order : {'C', 'F', 'A', 'K'}, optional\n",
      " |          Controls the memory layout of the copy. 'C' means C-order,\n",
      " |          'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,\n",
      " |          'C' otherwise. 'K' means match the layout of `a` as closely\n",
      " |          as possible. (Note that this function and :func:`numpy.copy` are very\n",
      " |          similar, but have different default values for their order=\n",
      " |          arguments.)\n",
      " |      \n",
      " |      See also\n",
      " |      --------\n",
      " |      numpy.copy\n",
      " |      numpy.copyto\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([[1,2,3],[4,5,6]], order='F')\n",
      " |      \n",
      " |      >>> y = x.copy()\n",
      " |      \n",
      " |      >>> x.fill(0)\n",
      " |      \n",
      " |      >>> x\n",
      " |      array([[0, 0, 0],\n",
      " |             [0, 0, 0]])\n",
      " |      \n",
      " |      >>> y\n",
      " |      array([[1, 2, 3],\n",
      " |             [4, 5, 6]])\n",
      " |      \n",
      " |      >>> y.flags['C_CONTIGUOUS']\n",
      " |      True\n",
      " |  \n",
      " |  cumprod(...)\n",
      " |      a.cumprod(axis=None, dtype=None, out=None)\n",
      " |      \n",
      " |      Return the cumulative product of the elements along the given axis.\n",
      " |      \n",
      " |      Refer to `numpy.cumprod` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.cumprod : equivalent function\n",
      " |  \n",
      " |  cumsum(...)\n",
      " |      a.cumsum(axis=None, dtype=None, out=None)\n",
      " |      \n",
      " |      Return the cumulative sum of the elements along the given axis.\n",
      " |      \n",
      " |      Refer to `numpy.cumsum` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.cumsum : equivalent function\n",
      " |  \n",
      " |  diagonal(...)\n",
      " |      a.diagonal(offset=0, axis1=0, axis2=1)\n",
      " |      \n",
      " |      Return specified diagonals. In NumPy 1.9 the returned array is a\n",
      " |      read-only view instead of a copy as in previous NumPy versions.  In\n",
      " |      a future version the read-only restriction will be removed.\n",
      " |      \n",
      " |      Refer to :func:`numpy.diagonal` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.diagonal : equivalent function\n",
      " |  \n",
      " |  dot(...)\n",
      " |      a.dot(b, out=None)\n",
      " |      \n",
      " |      Dot product of two arrays.\n",
      " |      \n",
      " |      Refer to `numpy.dot` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.dot : equivalent function\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.eye(2)\n",
      " |      >>> b = np.ones((2, 2)) * 2\n",
      " |      >>> a.dot(b)\n",
      " |      array([[ 2.,  2.],\n",
      " |             [ 2.,  2.]])\n",
      " |      \n",
      " |      This array method can be conveniently chained:\n",
      " |      \n",
      " |      >>> a.dot(b).dot(b)\n",
      " |      array([[ 8.,  8.],\n",
      " |             [ 8.,  8.]])\n",
      " |  \n",
      " |  dump(...)\n",
      " |      a.dump(file)\n",
      " |      \n",
      " |      Dump a pickle of the array to the specified file.\n",
      " |      The array can be read back with pickle.load or numpy.load.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      file : str\n",
      " |          A string naming the dump file.\n",
      " |  \n",
      " |  dumps(...)\n",
      " |      a.dumps()\n",
      " |      \n",
      " |      Returns the pickle of the array as a string.\n",
      " |      pickle.loads or numpy.loads will convert the string back to an array.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      None\n",
      " |  \n",
      " |  fill(...)\n",
      " |      a.fill(value)\n",
      " |      \n",
      " |      Fill the array with a scalar value.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      value : scalar\n",
      " |          All elements of `a` will be assigned this value.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([1, 2])\n",
      " |      >>> a.fill(0)\n",
      " |      >>> a\n",
      " |      array([0, 0])\n",
      " |      >>> a = np.empty(2)\n",
      " |      >>> a.fill(1)\n",
      " |      >>> a\n",
      " |      array([ 1.,  1.])\n",
      " |  \n",
      " |  flatten(...)\n",
      " |      a.flatten(order='C')\n",
      " |      \n",
      " |      Return a copy of the array collapsed into one dimension.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      order : {'C', 'F', 'A', 'K'}, optional\n",
      " |          'C' means to flatten in row-major (C-style) order.\n",
      " |          'F' means to flatten in column-major (Fortran-\n",
      " |          style) order. 'A' means to flatten in column-major\n",
      " |          order if `a` is Fortran *contiguous* in memory,\n",
      " |          row-major order otherwise. 'K' means to flatten\n",
      " |          `a` in the order the elements occur in memory.\n",
      " |          The default is 'C'.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      y : ndarray\n",
      " |          A copy of the input array, flattened to one dimension.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      ravel : Return a flattened array.\n",
      " |      flat : A 1-D flat iterator over the array.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([[1,2], [3,4]])\n",
      " |      >>> a.flatten()\n",
      " |      array([1, 2, 3, 4])\n",
      " |      >>> a.flatten('F')\n",
      " |      array([1, 3, 2, 4])\n",
      " |  \n",
      " |  getfield(...)\n",
      " |      a.getfield(dtype, offset=0)\n",
      " |      \n",
      " |      Returns a field of the given array as a certain type.\n",
      " |      \n",
      " |      A field is a view of the array data with a given data-type. The values in\n",
      " |      the view are determined by the given type and the offset into the current\n",
      " |      array in bytes. The offset needs to be such that the view dtype fits in the\n",
      " |      array dtype; for example an array of dtype complex128 has 16-byte elements.\n",
      " |      If taking a view with a 32-bit integer (4 bytes), the offset needs to be\n",
      " |      between 0 and 12 bytes.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      dtype : str or dtype\n",
      " |          The data type of the view. The dtype size of the view can not be larger\n",
      " |          than that of the array itself.\n",
      " |      offset : int\n",
      " |          Number of bytes to skip before beginning the element view.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.diag([1.+1.j]*2)\n",
      " |      >>> x[1, 1] = 2 + 4.j\n",
      " |      >>> x\n",
      " |      array([[ 1.+1.j,  0.+0.j],\n",
      " |             [ 0.+0.j,  2.+4.j]])\n",
      " |      >>> x.getfield(np.float64)\n",
      " |      array([[ 1.,  0.],\n",
      " |             [ 0.,  2.]])\n",
      " |      \n",
      " |      By choosing an offset of 8 bytes we can select the complex part of the\n",
      " |      array for our view:\n",
      " |      \n",
      " |      >>> x.getfield(np.float64, offset=8)\n",
      " |      array([[ 1.,  0.],\n",
      " |         [ 0.,  4.]])\n",
      " |  \n",
      " |  item(...)\n",
      " |      a.item(*args)\n",
      " |      \n",
      " |      Copy an element of an array to a standard Python scalar and return it.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      \\*args : Arguments (variable number and type)\n",
      " |      \n",
      " |          * none: in this case, the method only works for arrays\n",
      " |            with one element (`a.size == 1`), which element is\n",
      " |            copied into a standard Python scalar object and returned.\n",
      " |      \n",
      " |          * int_type: this argument is interpreted as a flat index into\n",
      " |            the array, specifying which element to copy and return.\n",
      " |      \n",
      " |          * tuple of int_types: functions as does a single int_type argument,\n",
      " |            except that the argument is interpreted as an nd-index into the\n",
      " |            array.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      z : Standard Python scalar object\n",
      " |          A copy of the specified element of the array as a suitable\n",
      " |          Python scalar\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      When the data type of `a` is longdouble or clongdouble, item() returns\n",
      " |      a scalar array object because there is no available Python scalar that\n",
      " |      would not lose information. Void arrays return a buffer object for item(),\n",
      " |      unless fields are defined, in which case a tuple is returned.\n",
      " |      \n",
      " |      `item` is very similar to a[args], except, instead of an array scalar,\n",
      " |      a standard Python scalar is returned. This can be useful for speeding up\n",
      " |      access to elements of the array and doing arithmetic on elements of the\n",
      " |      array using Python's optimized math.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.random.randint(9, size=(3, 3))\n",
      " |      >>> x\n",
      " |      array([[3, 1, 7],\n",
      " |             [2, 8, 3],\n",
      " |             [8, 5, 3]])\n",
      " |      >>> x.item(3)\n",
      " |      2\n",
      " |      >>> x.item(7)\n",
      " |      5\n",
      " |      >>> x.item((0, 1))\n",
      " |      1\n",
      " |      >>> x.item((2, 2))\n",
      " |      3\n",
      " |  \n",
      " |  itemset(...)\n",
      " |      a.itemset(*args)\n",
      " |      \n",
      " |      Insert scalar into an array (scalar is cast to array's dtype, if possible)\n",
      " |      \n",
      " |      There must be at least 1 argument, and define the last argument\n",
      " |      as *item*.  Then, ``a.itemset(*args)`` is equivalent to but faster\n",
      " |      than ``a[args] = item``.  The item should be a scalar value and `args`\n",
      " |      must select a single item in the array `a`.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      \\*args : Arguments\n",
      " |          If one argument: a scalar, only used in case `a` is of size 1.\n",
      " |          If two arguments: the last argument is the value to be set\n",
      " |          and must be a scalar, the first argument specifies a single array\n",
      " |          element location. It is either an int or a tuple.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Compared to indexing syntax, `itemset` provides some speed increase\n",
      " |      for placing a scalar into a particular location in an `ndarray`,\n",
      " |      if you must do this.  However, generally this is discouraged:\n",
      " |      among other problems, it complicates the appearance of the code.\n",
      " |      Also, when using `itemset` (and `item`) inside a loop, be sure\n",
      " |      to assign the methods to a local variable to avoid the attribute\n",
      " |      look-up at each loop iteration.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.random.randint(9, size=(3, 3))\n",
      " |      >>> x\n",
      " |      array([[3, 1, 7],\n",
      " |             [2, 8, 3],\n",
      " |             [8, 5, 3]])\n",
      " |      >>> x.itemset(4, 0)\n",
      " |      >>> x.itemset((2, 2), 9)\n",
      " |      >>> x\n",
      " |      array([[3, 1, 7],\n",
      " |             [2, 0, 3],\n",
      " |             [8, 5, 9]])\n",
      " |  \n",
      " |  max(...)\n",
      " |      a.max(axis=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Return the maximum along a given axis.\n",
      " |      \n",
      " |      Refer to `numpy.amax` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.amax : equivalent function\n",
      " |  \n",
      " |  mean(...)\n",
      " |      a.mean(axis=None, dtype=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Returns the average of the array elements along given axis.\n",
      " |      \n",
      " |      Refer to `numpy.mean` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.mean : equivalent function\n",
      " |  \n",
      " |  min(...)\n",
      " |      a.min(axis=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Return the minimum along a given axis.\n",
      " |      \n",
      " |      Refer to `numpy.amin` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.amin : equivalent function\n",
      " |  \n",
      " |  newbyteorder(...)\n",
      " |      arr.newbyteorder(new_order='S')\n",
      " |      \n",
      " |      Return the array with the same data viewed with a different byte order.\n",
      " |      \n",
      " |      Equivalent to::\n",
      " |      \n",
      " |          arr.view(arr.dtype.newbytorder(new_order))\n",
      " |      \n",
      " |      Changes are also made in all fields and sub-arrays of the array data\n",
      " |      type.\n",
      " |      \n",
      " |      \n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      new_order : string, optional\n",
      " |          Byte order to force; a value from the byte order specifications\n",
      " |          below. `new_order` codes can be any of:\n",
      " |      \n",
      " |          * 'S' - swap dtype from current to opposite endian\n",
      " |          * {'<', 'L'} - little endian\n",
      " |          * {'>', 'B'} - big endian\n",
      " |          * {'=', 'N'} - native order\n",
      " |          * {'|', 'I'} - ignore (no change to byte order)\n",
      " |      \n",
      " |          The default value ('S') results in swapping the current\n",
      " |          byte order. The code does a case-insensitive check on the first\n",
      " |          letter of `new_order` for the alternatives above.  For example,\n",
      " |          any of 'B' or 'b' or 'biggish' are valid to specify big-endian.\n",
      " |      \n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      new_arr : array\n",
      " |          New array object with the dtype reflecting given change to the\n",
      " |          byte order.\n",
      " |  \n",
      " |  nonzero(...)\n",
      " |      a.nonzero()\n",
      " |      \n",
      " |      Return the indices of the elements that are non-zero.\n",
      " |      \n",
      " |      Refer to `numpy.nonzero` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.nonzero : equivalent function\n",
      " |  \n",
      " |  partition(...)\n",
      " |      a.partition(kth, axis=-1, kind='introselect', order=None)\n",
      " |      \n",
      " |      Rearranges the elements in the array in such a way that value of the\n",
      " |      element in kth position is in the position it would be in a sorted array.\n",
      " |      All elements smaller than the kth element are moved before this element and\n",
      " |      all equal or greater are moved behind it. The ordering of the elements in\n",
      " |      the two partitions is undefined.\n",
      " |      \n",
      " |      .. versionadded:: 1.8.0\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      kth : int or sequence of ints\n",
      " |          Element index to partition by. The kth element value will be in its\n",
      " |          final sorted position and all smaller elements will be moved before it\n",
      " |          and all equal or greater elements behind it.\n",
      " |          The order all elements in the partitions is undefined.\n",
      " |          If provided with a sequence of kth it will partition all elements\n",
      " |          indexed by kth of them into their sorted position at once.\n",
      " |      axis : int, optional\n",
      " |          Axis along which to sort. Default is -1, which means sort along the\n",
      " |          last axis.\n",
      " |      kind : {'introselect'}, optional\n",
      " |          Selection algorithm. Default is 'introselect'.\n",
      " |      order : str or list of str, optional\n",
      " |          When `a` is an array with fields defined, this argument specifies\n",
      " |          which fields to compare first, second, etc.  A single field can\n",
      " |          be specified as a string, and not all fields need be specified,\n",
      " |          but unspecified fields will still be used, in the order in which\n",
      " |          they come up in the dtype, to break ties.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.partition : Return a parititioned copy of an array.\n",
      " |      argpartition : Indirect partition.\n",
      " |      sort : Full sort.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      See ``np.partition`` for notes on the different algorithms.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([3, 4, 2, 1])\n",
      " |      >>> a.partition(3)\n",
      " |      >>> a\n",
      " |      array([2, 1, 3, 4])\n",
      " |      \n",
      " |      >>> a.partition((1, 3))\n",
      " |      array([1, 2, 3, 4])\n",
      " |  \n",
      " |  prod(...)\n",
      " |      a.prod(axis=None, dtype=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Return the product of the array elements over the given axis\n",
      " |      \n",
      " |      Refer to `numpy.prod` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.prod : equivalent function\n",
      " |  \n",
      " |  ptp(...)\n",
      " |      a.ptp(axis=None, out=None)\n",
      " |      \n",
      " |      Peak to peak (maximum - minimum) value along a given axis.\n",
      " |      \n",
      " |      Refer to `numpy.ptp` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.ptp : equivalent function\n",
      " |  \n",
      " |  put(...)\n",
      " |      a.put(indices, values, mode='raise')\n",
      " |      \n",
      " |      Set ``a.flat[n] = values[n]`` for all `n` in indices.\n",
      " |      \n",
      " |      Refer to `numpy.put` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.put : equivalent function\n",
      " |  \n",
      " |  ravel(...)\n",
      " |      a.ravel([order])\n",
      " |      \n",
      " |      Return a flattened array.\n",
      " |      \n",
      " |      Refer to `numpy.ravel` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.ravel : equivalent function\n",
      " |      \n",
      " |      ndarray.flat : a flat iterator on the array.\n",
      " |  \n",
      " |  repeat(...)\n",
      " |      a.repeat(repeats, axis=None)\n",
      " |      \n",
      " |      Repeat elements of an array.\n",
      " |      \n",
      " |      Refer to `numpy.repeat` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.repeat : equivalent function\n",
      " |  \n",
      " |  reshape(...)\n",
      " |      a.reshape(shape, order='C')\n",
      " |      \n",
      " |      Returns an array containing the same data with a new shape.\n",
      " |      \n",
      " |      Refer to `numpy.reshape` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.reshape : equivalent function\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Unlike the free function `numpy.reshape`, this method on `ndarray` allows\n",
      " |      the elements of the shape parameter to be passed in as separate arguments.\n",
      " |      For example, ``a.reshape(10, 11)`` is equivalent to\n",
      " |      ``a.reshape((10, 11))``.\n",
      " |  \n",
      " |  resize(...)\n",
      " |      a.resize(new_shape, refcheck=True)\n",
      " |      \n",
      " |      Change shape and size of array in-place.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      new_shape : tuple of ints, or `n` ints\n",
      " |          Shape of resized array.\n",
      " |      refcheck : bool, optional\n",
      " |          If False, reference count will not be checked. Default is True.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      None\n",
      " |      \n",
      " |      Raises\n",
      " |      ------\n",
      " |      ValueError\n",
      " |          If `a` does not own its own data or references or views to it exist,\n",
      " |          and the data memory must be changed.\n",
      " |          PyPy only: will always raise if the data memory must be changed, since\n",
      " |          there is no reliable way to determine if references or views to it\n",
      " |          exist.\n",
      " |      \n",
      " |      SystemError\n",
      " |          If the `order` keyword argument is specified. This behaviour is a\n",
      " |          bug in NumPy.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      resize : Return a new array with the specified shape.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      This reallocates space for the data area if necessary.\n",
      " |      \n",
      " |      Only contiguous arrays (data elements consecutive in memory) can be\n",
      " |      resized.\n",
      " |      \n",
      " |      The purpose of the reference count check is to make sure you\n",
      " |      do not use this array as a buffer for another Python object and then\n",
      " |      reallocate the memory. However, reference counts can increase in\n",
      " |      other ways so if you are sure that you have not shared the memory\n",
      " |      for this array with another Python object, then you may safely set\n",
      " |      `refcheck` to False.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      Shrinking an array: array is flattened (in the order that the data are\n",
      " |      stored in memory), resized, and reshaped:\n",
      " |      \n",
      " |      >>> a = np.array([[0, 1], [2, 3]], order='C')\n",
      " |      >>> a.resize((2, 1))\n",
      " |      >>> a\n",
      " |      array([[0],\n",
      " |             [1]])\n",
      " |      \n",
      " |      >>> a = np.array([[0, 1], [2, 3]], order='F')\n",
      " |      >>> a.resize((2, 1))\n",
      " |      >>> a\n",
      " |      array([[0],\n",
      " |             [2]])\n",
      " |      \n",
      " |      Enlarging an array: as above, but missing entries are filled with zeros:\n",
      " |      \n",
      " |      >>> b = np.array([[0, 1], [2, 3]])\n",
      " |      >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple\n",
      " |      >>> b\n",
      " |      array([[0, 1, 2],\n",
      " |             [3, 0, 0]])\n",
      " |      \n",
      " |      Referencing an array prevents resizing...\n",
      " |      \n",
      " |      >>> c = a\n",
      " |      >>> a.resize((1, 1))\n",
      " |      Traceback (most recent call last):\n",
      " |      ...\n",
      " |      ValueError: cannot resize an array that has been referenced ...\n",
      " |      \n",
      " |      Unless `refcheck` is False:\n",
      " |      \n",
      " |      >>> a.resize((1, 1), refcheck=False)\n",
      " |      >>> a\n",
      " |      array([[0]])\n",
      " |      >>> c\n",
      " |      array([[0]])\n",
      " |  \n",
      " |  round(...)\n",
      " |      a.round(decimals=0, out=None)\n",
      " |      \n",
      " |      Return `a` with each element rounded to the given number of decimals.\n",
      " |      \n",
      " |      Refer to `numpy.around` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.around : equivalent function\n",
      " |  \n",
      " |  searchsorted(...)\n",
      " |      a.searchsorted(v, side='left', sorter=None)\n",
      " |      \n",
      " |      Find indices where elements of v should be inserted in a to maintain order.\n",
      " |      \n",
      " |      For full documentation, see `numpy.searchsorted`\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.searchsorted : equivalent function\n",
      " |  \n",
      " |  setfield(...)\n",
      " |      a.setfield(val, dtype, offset=0)\n",
      " |      \n",
      " |      Put a value into a specified place in a field defined by a data-type.\n",
      " |      \n",
      " |      Place `val` into `a`'s field defined by `dtype` and beginning `offset`\n",
      " |      bytes into the field.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      val : object\n",
      " |          Value to be placed in field.\n",
      " |      dtype : dtype object\n",
      " |          Data-type of the field in which to place `val`.\n",
      " |      offset : int, optional\n",
      " |          The number of bytes into the field at which to place `val`.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      None\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      getfield\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.eye(3)\n",
      " |      >>> x.getfield(np.float64)\n",
      " |      array([[ 1.,  0.,  0.],\n",
      " |             [ 0.,  1.,  0.],\n",
      " |             [ 0.,  0.,  1.]])\n",
      " |      >>> x.setfield(3, np.int32)\n",
      " |      >>> x.getfield(np.int32)\n",
      " |      array([[3, 3, 3],\n",
      " |             [3, 3, 3],\n",
      " |             [3, 3, 3]])\n",
      " |      >>> x\n",
      " |      array([[  1.00000000e+000,   1.48219694e-323,   1.48219694e-323],\n",
      " |             [  1.48219694e-323,   1.00000000e+000,   1.48219694e-323],\n",
      " |             [  1.48219694e-323,   1.48219694e-323,   1.00000000e+000]])\n",
      " |      >>> x.setfield(np.eye(3), np.int32)\n",
      " |      >>> x\n",
      " |      array([[ 1.,  0.,  0.],\n",
      " |             [ 0.,  1.,  0.],\n",
      " |             [ 0.,  0.,  1.]])\n",
      " |  \n",
      " |  setflags(...)\n",
      " |      a.setflags(write=None, align=None, uic=None)\n",
      " |      \n",
      " |      Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY),\n",
      " |      respectively.\n",
      " |      \n",
      " |      These Boolean-valued flags affect how numpy interprets the memory\n",
      " |      area used by `a` (see Notes below). The ALIGNED flag can only\n",
      " |      be set to True if the data is actually aligned according to the type.\n",
      " |      The WRITEBACKIFCOPY and (deprecated) UPDATEIFCOPY flags can never be set\n",
      " |      to True. The flag WRITEABLE can only be set to True if the array owns its\n",
      " |      own memory, or the ultimate owner of the memory exposes a writeable buffer\n",
      " |      interface, or is a string. (The exception for string is made so that\n",
      " |      unpickling can be done without copying memory.)\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      write : bool, optional\n",
      " |          Describes whether or not `a` can be written to.\n",
      " |      align : bool, optional\n",
      " |          Describes whether or not `a` is aligned properly for its type.\n",
      " |      uic : bool, optional\n",
      " |          Describes whether or not `a` is a copy of another \"base\" array.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Array flags provide information about how the memory area used\n",
      " |      for the array is to be interpreted. There are 7 Boolean flags\n",
      " |      in use, only four of which can be changed by the user:\n",
      " |      WRITEBACKIFCOPY, UPDATEIFCOPY, WRITEABLE, and ALIGNED.\n",
      " |      \n",
      " |      WRITEABLE (W) the data area can be written to;\n",
      " |      \n",
      " |      ALIGNED (A) the data and strides are aligned appropriately for the hardware\n",
      " |      (as determined by the compiler);\n",
      " |      \n",
      " |      UPDATEIFCOPY (U) (deprecated), replaced by WRITEBACKIFCOPY;\n",
      " |      \n",
      " |      WRITEBACKIFCOPY (X) this array is a copy of some other array (referenced\n",
      " |      by .base). When the C-API function PyArray_ResolveWritebackIfCopy is\n",
      " |      called, the base array will be updated with the contents of this array.\n",
      " |      \n",
      " |      All flags can be accessed using the single (upper case) letter as well\n",
      " |      as the full name.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> y\n",
      " |      array([[3, 1, 7],\n",
      " |             [2, 0, 0],\n",
      " |             [8, 5, 9]])\n",
      " |      >>> y.flags\n",
      " |        C_CONTIGUOUS : True\n",
      " |        F_CONTIGUOUS : False\n",
      " |        OWNDATA : True\n",
      " |        WRITEABLE : True\n",
      " |        ALIGNED : True\n",
      " |        WRITEBACKIFCOPY : False\n",
      " |        UPDATEIFCOPY : False\n",
      " |      >>> y.setflags(write=0, align=0)\n",
      " |      >>> y.flags\n",
      " |        C_CONTIGUOUS : True\n",
      " |        F_CONTIGUOUS : False\n",
      " |        OWNDATA : True\n",
      " |        WRITEABLE : False\n",
      " |        ALIGNED : False\n",
      " |        WRITEBACKIFCOPY : False\n",
      " |        UPDATEIFCOPY : False\n",
      " |      >>> y.setflags(uic=1)\n",
      " |      Traceback (most recent call last):\n",
      " |        File \"<stdin>\", line 1, in <module>\n",
      " |      ValueError: cannot set WRITEBACKIFCOPY flag to True\n",
      " |  \n",
      " |  sort(...)\n",
      " |      a.sort(axis=-1, kind='quicksort', order=None)\n",
      " |      \n",
      " |      Sort an array, in-place.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      axis : int, optional\n",
      " |          Axis along which to sort. Default is -1, which means sort along the\n",
      " |          last axis.\n",
      " |      kind : {'quicksort', 'mergesort', 'heapsort'}, optional\n",
      " |          Sorting algorithm. Default is 'quicksort'.\n",
      " |      order : str or list of str, optional\n",
      " |          When `a` is an array with fields defined, this argument specifies\n",
      " |          which fields to compare first, second, etc.  A single field can\n",
      " |          be specified as a string, and not all fields need be specified,\n",
      " |          but unspecified fields will still be used, in the order in which\n",
      " |          they come up in the dtype, to break ties.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.sort : Return a sorted copy of an array.\n",
      " |      argsort : Indirect sort.\n",
      " |      lexsort : Indirect stable sort on multiple keys.\n",
      " |      searchsorted : Find elements in sorted array.\n",
      " |      partition: Partial sort.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      See ``sort`` for notes on the different sorting algorithms.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([[1,4], [3,1]])\n",
      " |      >>> a.sort(axis=1)\n",
      " |      >>> a\n",
      " |      array([[1, 4],\n",
      " |             [1, 3]])\n",
      " |      >>> a.sort(axis=0)\n",
      " |      >>> a\n",
      " |      array([[1, 3],\n",
      " |             [1, 4]])\n",
      " |      \n",
      " |      Use the `order` keyword to specify a field to use when sorting a\n",
      " |      structured array:\n",
      " |      \n",
      " |      >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)])\n",
      " |      >>> a.sort(order='y')\n",
      " |      >>> a\n",
      " |      array([('c', 1), ('a', 2)],\n",
      " |            dtype=[('x', '|S1'), ('y', '<i4')])\n",
      " |  \n",
      " |  squeeze(...)\n",
      " |      a.squeeze(axis=None)\n",
      " |      \n",
      " |      Remove single-dimensional entries from the shape of `a`.\n",
      " |      \n",
      " |      Refer to `numpy.squeeze` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.squeeze : equivalent function\n",
      " |  \n",
      " |  std(...)\n",
      " |      a.std(axis=None, dtype=None, out=None, ddof=0, keepdims=False)\n",
      " |      \n",
      " |      Returns the standard deviation of the array elements along given axis.\n",
      " |      \n",
      " |      Refer to `numpy.std` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.std : equivalent function\n",
      " |  \n",
      " |  sum(...)\n",
      " |      a.sum(axis=None, dtype=None, out=None, keepdims=False)\n",
      " |      \n",
      " |      Return the sum of the array elements over the given axis.\n",
      " |      \n",
      " |      Refer to `numpy.sum` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.sum : equivalent function\n",
      " |  \n",
      " |  swapaxes(...)\n",
      " |      a.swapaxes(axis1, axis2)\n",
      " |      \n",
      " |      Return a view of the array with `axis1` and `axis2` interchanged.\n",
      " |      \n",
      " |      Refer to `numpy.swapaxes` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.swapaxes : equivalent function\n",
      " |  \n",
      " |  take(...)\n",
      " |      a.take(indices, axis=None, out=None, mode='raise')\n",
      " |      \n",
      " |      Return an array formed from the elements of `a` at the given indices.\n",
      " |      \n",
      " |      Refer to `numpy.take` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.take : equivalent function\n",
      " |  \n",
      " |  tobytes(...)\n",
      " |      a.tobytes(order='C')\n",
      " |      \n",
      " |      Construct Python bytes containing the raw data bytes in the array.\n",
      " |      \n",
      " |      Constructs Python bytes showing a copy of the raw contents of\n",
      " |      data memory. The bytes object can be produced in either 'C' or 'Fortran',\n",
      " |      or 'Any' order (the default is 'C'-order). 'Any' order means C-order\n",
      " |      unless the F_CONTIGUOUS flag in the array is set, in which case it\n",
      " |      means 'Fortran' order.\n",
      " |      \n",
      " |      .. versionadded:: 1.9.0\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      order : {'C', 'F', None}, optional\n",
      " |          Order of the data for multidimensional arrays:\n",
      " |          C, Fortran, or the same as for the original array.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      s : bytes\n",
      " |          Python bytes exhibiting a copy of `a`'s raw data.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([[0, 1], [2, 3]])\n",
      " |      >>> x.tobytes()\n",
      " |      b'\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x03\\x00\\x00\\x00'\n",
      " |      >>> x.tobytes('C') == x.tobytes()\n",
      " |      True\n",
      " |      >>> x.tobytes('F')\n",
      " |      b'\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x03\\x00\\x00\\x00'\n",
      " |  \n",
      " |  tofile(...)\n",
      " |      a.tofile(fid, sep=\"\", format=\"%s\")\n",
      " |      \n",
      " |      Write array to a file as text or binary (default).\n",
      " |      \n",
      " |      Data is always written in 'C' order, independent of the order of `a`.\n",
      " |      The data produced by this method can be recovered using the function\n",
      " |      fromfile().\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      fid : file or str\n",
      " |          An open file object, or a string containing a filename.\n",
      " |      sep : str\n",
      " |          Separator between array items for text output.\n",
      " |          If \"\" (empty), a binary file is written, equivalent to\n",
      " |          ``file.write(a.tobytes())``.\n",
      " |      format : str\n",
      " |          Format string for text file output.\n",
      " |          Each entry in the array is formatted to text by first converting\n",
      " |          it to the closest Python type, and then using \"format\" % item.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      This is a convenience function for quick storage of array data.\n",
      " |      Information on endianness and precision is lost, so this method is not a\n",
      " |      good choice for files intended to archive data or transport data between\n",
      " |      machines with different endianness. Some of these problems can be overcome\n",
      " |      by outputting the data as text files, at the expense of speed and file\n",
      " |      size.\n",
      " |  \n",
      " |  tolist(...)\n",
      " |      a.tolist()\n",
      " |      \n",
      " |      Return the array as a (possibly nested) list.\n",
      " |      \n",
      " |      Return a copy of the array data as a (nested) Python list.\n",
      " |      Data items are converted to the nearest compatible Python type.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      none\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      y : list\n",
      " |          The possibly nested list of array elements.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      The array may be recreated, ``a = np.array(a.tolist())``.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([1, 2])\n",
      " |      >>> a.tolist()\n",
      " |      [1, 2]\n",
      " |      >>> a = np.array([[1, 2], [3, 4]])\n",
      " |      >>> list(a)\n",
      " |      [array([1, 2]), array([3, 4])]\n",
      " |      >>> a.tolist()\n",
      " |      [[1, 2], [3, 4]]\n",
      " |  \n",
      " |  tostring(...)\n",
      " |      a.tostring(order='C')\n",
      " |      \n",
      " |      Construct Python bytes containing the raw data bytes in the array.\n",
      " |      \n",
      " |      Constructs Python bytes showing a copy of the raw contents of\n",
      " |      data memory. The bytes object can be produced in either 'C' or 'Fortran',\n",
      " |      or 'Any' order (the default is 'C'-order). 'Any' order means C-order\n",
      " |      unless the F_CONTIGUOUS flag in the array is set, in which case it\n",
      " |      means 'Fortran' order.\n",
      " |      \n",
      " |      This function is a compatibility alias for tobytes. Despite its name it returns bytes not strings.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      order : {'C', 'F', None}, optional\n",
      " |          Order of the data for multidimensional arrays:\n",
      " |          C, Fortran, or the same as for the original array.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      s : bytes\n",
      " |          Python bytes exhibiting a copy of `a`'s raw data.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([[0, 1], [2, 3]])\n",
      " |      >>> x.tobytes()\n",
      " |      b'\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x03\\x00\\x00\\x00'\n",
      " |      >>> x.tobytes('C') == x.tobytes()\n",
      " |      True\n",
      " |      >>> x.tobytes('F')\n",
      " |      b'\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x03\\x00\\x00\\x00'\n",
      " |  \n",
      " |  trace(...)\n",
      " |      a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)\n",
      " |      \n",
      " |      Return the sum along diagonals of the array.\n",
      " |      \n",
      " |      Refer to `numpy.trace` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.trace : equivalent function\n",
      " |  \n",
      " |  transpose(...)\n",
      " |      a.transpose(*axes)\n",
      " |      \n",
      " |      Returns a view of the array with axes transposed.\n",
      " |      \n",
      " |      For a 1-D array, this has no effect. (To change between column and\n",
      " |      row vectors, first cast the 1-D array into a matrix object.)\n",
      " |      For a 2-D array, this is the usual matrix transpose.\n",
      " |      For an n-D array, if axes are given, their order indicates how the\n",
      " |      axes are permuted (see Examples). If axes are not provided and\n",
      " |      ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then\n",
      " |      ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      axes : None, tuple of ints, or `n` ints\n",
      " |      \n",
      " |       * None or no argument: reverses the order of the axes.\n",
      " |      \n",
      " |       * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s\n",
      " |         `i`-th axis becomes `a.transpose()`'s `j`-th axis.\n",
      " |      \n",
      " |       * `n` ints: same as an n-tuple of the same ints (this form is\n",
      " |         intended simply as a \"convenience\" alternative to the tuple form)\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      out : ndarray\n",
      " |          View of `a`, with axes suitably permuted.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      ndarray.T : Array property returning the array transposed.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> a = np.array([[1, 2], [3, 4]])\n",
      " |      >>> a\n",
      " |      array([[1, 2],\n",
      " |             [3, 4]])\n",
      " |      >>> a.transpose()\n",
      " |      array([[1, 3],\n",
      " |             [2, 4]])\n",
      " |      >>> a.transpose((1, 0))\n",
      " |      array([[1, 3],\n",
      " |             [2, 4]])\n",
      " |      >>> a.transpose(1, 0)\n",
      " |      array([[1, 3],\n",
      " |             [2, 4]])\n",
      " |  \n",
      " |  var(...)\n",
      " |      a.var(axis=None, dtype=None, out=None, ddof=0, keepdims=False)\n",
      " |      \n",
      " |      Returns the variance of the array elements, along given axis.\n",
      " |      \n",
      " |      Refer to `numpy.var` for full documentation.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.var : equivalent function\n",
      " |  \n",
      " |  view(...)\n",
      " |      a.view(dtype=None, type=None)\n",
      " |      \n",
      " |      New view of array with the same data.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      dtype : data-type or ndarray sub-class, optional\n",
      " |          Data-type descriptor of the returned view, e.g., float32 or int16. The\n",
      " |          default, None, results in the view having the same data-type as `a`.\n",
      " |          This argument can also be specified as an ndarray sub-class, which\n",
      " |          then specifies the type of the returned object (this is equivalent to\n",
      " |          setting the ``type`` parameter).\n",
      " |      type : Python type, optional\n",
      " |          Type of the returned view, e.g., ndarray or matrix.  Again, the\n",
      " |          default None results in type preservation.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      ``a.view()`` is used two different ways:\n",
      " |      \n",
      " |      ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view\n",
      " |      of the array's memory with a different data-type.  This can cause a\n",
      " |      reinterpretation of the bytes of memory.\n",
      " |      \n",
      " |      ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just\n",
      " |      returns an instance of `ndarray_subclass` that looks at the same array\n",
      " |      (same shape, dtype, etc.)  This does not cause a reinterpretation of the\n",
      " |      memory.\n",
      " |      \n",
      " |      For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of\n",
      " |      bytes per entry than the previous dtype (for example, converting a\n",
      " |      regular array to a structured array), then the behavior of the view\n",
      " |      cannot be predicted just from the superficial appearance of ``a`` (shown\n",
      " |      by ``print(a)``). It also depends on exactly how ``a`` is stored in\n",
      " |      memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus\n",
      " |      defined as a slice or transpose, etc., the view may give different\n",
      " |      results.\n",
      " |      \n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)])\n",
      " |      \n",
      " |      Viewing array data using a different type and dtype:\n",
      " |      \n",
      " |      >>> y = x.view(dtype=np.int16, type=np.matrix)\n",
      " |      >>> y\n",
      " |      matrix([[513]], dtype=int16)\n",
      " |      >>> print(type(y))\n",
      " |      <class 'numpy.matrixlib.defmatrix.matrix'>\n",
      " |      \n",
      " |      Creating a view on a structured array so it can be used in calculations\n",
      " |      \n",
      " |      >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)])\n",
      " |      >>> xv = x.view(dtype=np.int8).reshape(-1,2)\n",
      " |      >>> xv\n",
      " |      array([[1, 2],\n",
      " |             [3, 4]], dtype=int8)\n",
      " |      >>> xv.mean(0)\n",
      " |      array([ 2.,  3.])\n",
      " |      \n",
      " |      Making changes to the view changes the underlying array\n",
      " |      \n",
      " |      >>> xv[0,1] = 20\n",
      " |      >>> print(x)\n",
      " |      [(1, 20) (3, 4)]\n",
      " |      \n",
      " |      Using a view to convert an array to a recarray:\n",
      " |      \n",
      " |      >>> z = x.view(np.recarray)\n",
      " |      >>> z.a\n",
      " |      array([1], dtype=int8)\n",
      " |      \n",
      " |      Views share data:\n",
      " |      \n",
      " |      >>> x[0] = (9, 10)\n",
      " |      >>> z[0]\n",
      " |      (9, 10)\n",
      " |      \n",
      " |      Views that change the dtype size (bytes per entry) should normally be\n",
      " |      avoided on arrays defined by slices, transposes, fortran-ordering, etc.:\n",
      " |      \n",
      " |      >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16)\n",
      " |      >>> y = x[:, 0:2]\n",
      " |      >>> y\n",
      " |      array([[1, 2],\n",
      " |             [4, 5]], dtype=int16)\n",
      " |      >>> y.view(dtype=[('width', np.int16), ('length', np.int16)])\n",
      " |      Traceback (most recent call last):\n",
      " |        File \"<stdin>\", line 1, in <module>\n",
      " |      ValueError: new type not compatible with array.\n",
      " |      >>> z = y.copy()\n",
      " |      >>> z.view(dtype=[('width', np.int16), ('length', np.int16)])\n",
      " |      array([[(1, 2)],\n",
      " |             [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  T\n",
      " |      Same as self.transpose(), except that self is returned if\n",
      " |      self.ndim < 2.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([[1.,2.],[3.,4.]])\n",
      " |      >>> x\n",
      " |      array([[ 1.,  2.],\n",
      " |             [ 3.,  4.]])\n",
      " |      >>> x.T\n",
      " |      array([[ 1.,  3.],\n",
      " |             [ 2.,  4.]])\n",
      " |      >>> x = np.array([1.,2.,3.,4.])\n",
      " |      >>> x\n",
      " |      array([ 1.,  2.,  3.,  4.])\n",
      " |      >>> x.T\n",
      " |      array([ 1.,  2.,  3.,  4.])\n",
      " |  \n",
      " |  __array_finalize__\n",
      " |      None.\n",
      " |  \n",
      " |  __array_interface__\n",
      " |      Array protocol: Python side.\n",
      " |  \n",
      " |  __array_priority__\n",
      " |      Array priority.\n",
      " |  \n",
      " |  __array_struct__\n",
      " |      Array protocol: C-struct side.\n",
      " |  \n",
      " |  base\n",
      " |      Base object if memory is from some other object.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      The base of an array that owns its memory is None:\n",
      " |      \n",
      " |      >>> x = np.array([1,2,3,4])\n",
      " |      >>> x.base is None\n",
      " |      True\n",
      " |      \n",
      " |      Slicing creates a view, whose memory is shared with x:\n",
      " |      \n",
      " |      >>> y = x[2:]\n",
      " |      >>> y.base is x\n",
      " |      True\n",
      " |  \n",
      " |  ctypes\n",
      " |      An object to simplify the interaction of the array with the ctypes\n",
      " |      module.\n",
      " |      \n",
      " |      This attribute creates an object that makes it easier to use arrays\n",
      " |      when calling shared libraries with the ctypes module. The returned\n",
      " |      object has, among others, data, shape, and strides attributes (see\n",
      " |      Notes below) which themselves return ctypes objects that can be used\n",
      " |      as arguments to a shared library.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      None\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      c : Python object\n",
      " |          Possessing attributes data, shape, strides, etc.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.ctypeslib\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Below are the public attributes of this object which were documented\n",
      " |      in \"Guide to NumPy\" (we have omitted undocumented public attributes,\n",
      " |      as well as documented private attributes):\n",
      " |      \n",
      " |      * data: A pointer to the memory area of the array as a Python integer.\n",
      " |        This memory area may contain data that is not aligned, or not in correct\n",
      " |        byte-order. The memory area may not even be writeable. The array\n",
      " |        flags and data-type of this array should be respected when passing this\n",
      " |        attribute to arbitrary C-code to avoid trouble that can include Python\n",
      " |        crashing. User Beware! The value of this attribute is exactly the same\n",
      " |        as self._array_interface_['data'][0].\n",
      " |      \n",
      " |      * shape (c_intp*self.ndim): A ctypes array of length self.ndim where\n",
      " |        the basetype is the C-integer corresponding to dtype('p') on this\n",
      " |        platform. This base-type could be c_int, c_long, or c_longlong\n",
      " |        depending on the platform. The c_intp type is defined accordingly in\n",
      " |        numpy.ctypeslib. The ctypes array contains the shape of the underlying\n",
      " |        array.\n",
      " |      \n",
      " |      * strides (c_intp*self.ndim): A ctypes array of length self.ndim where\n",
      " |        the basetype is the same as for the shape attribute. This ctypes array\n",
      " |        contains the strides information from the underlying array. This strides\n",
      " |        information is important for showing how many bytes must be jumped to\n",
      " |        get to the next element in the array.\n",
      " |      \n",
      " |      * data_as(obj): Return the data pointer cast to a particular c-types object.\n",
      " |        For example, calling self._as_parameter_ is equivalent to\n",
      " |        self.data_as(ctypes.c_void_p). Perhaps you want to use the data as a\n",
      " |        pointer to a ctypes array of floating-point data:\n",
      " |        self.data_as(ctypes.POINTER(ctypes.c_double)).\n",
      " |      \n",
      " |      * shape_as(obj): Return the shape tuple as an array of some other c-types\n",
      " |        type. For example: self.shape_as(ctypes.c_short).\n",
      " |      \n",
      " |      * strides_as(obj): Return the strides tuple as an array of some other\n",
      " |        c-types type. For example: self.strides_as(ctypes.c_longlong).\n",
      " |      \n",
      " |      Be careful using the ctypes attribute - especially on temporary\n",
      " |      arrays or arrays constructed on the fly. For example, calling\n",
      " |      ``(a+b).ctypes.data_as(ctypes.c_void_p)`` returns a pointer to memory\n",
      " |      that is invalid because the array created as (a+b) is deallocated\n",
      " |      before the next Python statement. You can avoid this problem using\n",
      " |      either ``c=a+b`` or ``ct=(a+b).ctypes``. In the latter case, ct will\n",
      " |      hold a reference to the array until ct is deleted or re-assigned.\n",
      " |      \n",
      " |      If the ctypes module is not available, then the ctypes attribute\n",
      " |      of array objects still returns something useful, but ctypes objects\n",
      " |      are not returned and errors may be raised instead. In particular,\n",
      " |      the object will still have the as parameter attribute which will\n",
      " |      return an integer equal to the data attribute.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> import ctypes\n",
      " |      >>> x\n",
      " |      array([[0, 1],\n",
      " |             [2, 3]])\n",
      " |      >>> x.ctypes.data\n",
      " |      30439712\n",
      " |      >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long))\n",
      " |      <ctypes.LP_c_long object at 0x01F01300>\n",
      " |      >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long)).contents\n",
      " |      c_long(0)\n",
      " |      >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_longlong)).contents\n",
      " |      c_longlong(4294967296L)\n",
      " |      >>> x.ctypes.shape\n",
      " |      <numpy.core._internal.c_long_Array_2 object at 0x01FFD580>\n",
      " |      >>> x.ctypes.shape_as(ctypes.c_long)\n",
      " |      <numpy.core._internal.c_long_Array_2 object at 0x01FCE620>\n",
      " |      >>> x.ctypes.strides\n",
      " |      <numpy.core._internal.c_long_Array_2 object at 0x01FCE620>\n",
      " |      >>> x.ctypes.strides_as(ctypes.c_longlong)\n",
      " |      <numpy.core._internal.c_longlong_Array_2 object at 0x01F01300>\n",
      " |  \n",
      " |  data\n",
      " |      Python buffer object pointing to the start of the array's data.\n",
      " |  \n",
      " |  dtype\n",
      " |      Data-type of the array's elements.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      None\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      d : numpy dtype object\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.dtype\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x\n",
      " |      array([[0, 1],\n",
      " |             [2, 3]])\n",
      " |      >>> x.dtype\n",
      " |      dtype('int32')\n",
      " |      >>> type(x.dtype)\n",
      " |      <type 'numpy.dtype'>\n",
      " |  \n",
      " |  flags\n",
      " |      Information about the memory layout of the array.\n",
      " |      \n",
      " |      Attributes\n",
      " |      ----------\n",
      " |      C_CONTIGUOUS (C)\n",
      " |          The data is in a single, C-style contiguous segment.\n",
      " |      F_CONTIGUOUS (F)\n",
      " |          The data is in a single, Fortran-style contiguous segment.\n",
      " |      OWNDATA (O)\n",
      " |          The array owns the memory it uses or borrows it from another object.\n",
      " |      WRITEABLE (W)\n",
      " |          The data area can be written to.  Setting this to False locks\n",
      " |          the data, making it read-only.  A view (slice, etc.) inherits WRITEABLE\n",
      " |          from its base array at creation time, but a view of a writeable\n",
      " |          array may be subsequently locked while the base array remains writeable.\n",
      " |          (The opposite is not true, in that a view of a locked array may not\n",
      " |          be made writeable.  However, currently, locking a base object does not\n",
      " |          lock any views that already reference it, so under that circumstance it\n",
      " |          is possible to alter the contents of a locked array via a previously\n",
      " |          created writeable view onto it.)  Attempting to change a non-writeable\n",
      " |          array raises a RuntimeError exception.\n",
      " |      ALIGNED (A)\n",
      " |          The data and all elements are aligned appropriately for the hardware.\n",
      " |      WRITEBACKIFCOPY (X)\n",
      " |          This array is a copy of some other array. The C-API function\n",
      " |          PyArray_ResolveWritebackIfCopy must be called before deallocating\n",
      " |          to the base array will be updated with the contents of this array.\n",
      " |      UPDATEIFCOPY (U)\n",
      " |          (Deprecated, use WRITEBACKIFCOPY) This array is a copy of some other array.\n",
      " |          When this array is\n",
      " |          deallocated, the base array will be updated with the contents of\n",
      " |          this array.\n",
      " |      FNC\n",
      " |          F_CONTIGUOUS and not C_CONTIGUOUS.\n",
      " |      FORC\n",
      " |          F_CONTIGUOUS or C_CONTIGUOUS (one-segment test).\n",
      " |      BEHAVED (B)\n",
      " |          ALIGNED and WRITEABLE.\n",
      " |      CARRAY (CA)\n",
      " |          BEHAVED and C_CONTIGUOUS.\n",
      " |      FARRAY (FA)\n",
      " |          BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      The `flags` object can be accessed dictionary-like (as in ``a.flags['WRITEABLE']``),\n",
      " |      or by using lowercased attribute names (as in ``a.flags.writeable``). Short flag\n",
      " |      names are only supported in dictionary access.\n",
      " |      \n",
      " |      Only the WRITEBACKIFCOPY, UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be\n",
      " |      changed by the user, via direct assignment to the attribute or dictionary\n",
      " |      entry, or by calling `ndarray.setflags`.\n",
      " |      \n",
      " |      The array flags cannot be set arbitrarily:\n",
      " |      \n",
      " |      - UPDATEIFCOPY can only be set ``False``.\n",
      " |      - WRITEBACKIFCOPY can only be set ``False``.\n",
      " |      - ALIGNED can only be set ``True`` if the data is truly aligned.\n",
      " |      - WRITEABLE can only be set ``True`` if the array owns its own memory\n",
      " |        or the ultimate owner of the memory exposes a writeable buffer\n",
      " |        interface or is a string.\n",
      " |      \n",
      " |      Arrays can be both C-style and Fortran-style contiguous simultaneously.\n",
      " |      This is clear for 1-dimensional arrays, but can also be true for higher\n",
      " |      dimensional arrays.\n",
      " |      \n",
      " |      Even for contiguous arrays a stride for a given dimension\n",
      " |      ``arr.strides[dim]`` may be *arbitrary* if ``arr.shape[dim] == 1``\n",
      " |      or the array has no elements.\n",
      " |      It does *not* generally hold that ``self.strides[-1] == self.itemsize``\n",
      " |      for C-style contiguous arrays or ``self.strides[0] == self.itemsize`` for\n",
      " |      Fortran-style contiguous arrays is true.\n",
      " |  \n",
      " |  flat\n",
      " |      A 1-D iterator over the array.\n",
      " |      \n",
      " |      This is a `numpy.flatiter` instance, which acts similarly to, but is not\n",
      " |      a subclass of, Python's built-in iterator object.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      flatten : Return a copy of the array collapsed into one dimension.\n",
      " |      \n",
      " |      flatiter\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.arange(1, 7).reshape(2, 3)\n",
      " |      >>> x\n",
      " |      array([[1, 2, 3],\n",
      " |             [4, 5, 6]])\n",
      " |      >>> x.flat[3]\n",
      " |      4\n",
      " |      >>> x.T\n",
      " |      array([[1, 4],\n",
      " |             [2, 5],\n",
      " |             [3, 6]])\n",
      " |      >>> x.T.flat[3]\n",
      " |      5\n",
      " |      >>> type(x.flat)\n",
      " |      <type 'numpy.flatiter'>\n",
      " |      \n",
      " |      An assignment example:\n",
      " |      \n",
      " |      >>> x.flat = 3; x\n",
      " |      array([[3, 3, 3],\n",
      " |             [3, 3, 3]])\n",
      " |      >>> x.flat[[1,4]] = 1; x\n",
      " |      array([[3, 1, 3],\n",
      " |             [3, 1, 3]])\n",
      " |  \n",
      " |  imag\n",
      " |      The imaginary part of the array.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.sqrt([1+0j, 0+1j])\n",
      " |      >>> x.imag\n",
      " |      array([ 0.        ,  0.70710678])\n",
      " |      >>> x.imag.dtype\n",
      " |      dtype('float64')\n",
      " |  \n",
      " |  itemsize\n",
      " |      Length of one array element in bytes.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([1,2,3], dtype=np.float64)\n",
      " |      >>> x.itemsize\n",
      " |      8\n",
      " |      >>> x = np.array([1,2,3], dtype=np.complex128)\n",
      " |      >>> x.itemsize\n",
      " |      16\n",
      " |  \n",
      " |  nbytes\n",
      " |      Total bytes consumed by the elements of the array.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Does not include memory consumed by non-element attributes of the\n",
      " |      array object.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.zeros((3,5,2), dtype=np.complex128)\n",
      " |      >>> x.nbytes\n",
      " |      480\n",
      " |      >>> np.prod(x.shape) * x.itemsize\n",
      " |      480\n",
      " |  \n",
      " |  ndim\n",
      " |      Number of array dimensions.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([1, 2, 3])\n",
      " |      >>> x.ndim\n",
      " |      1\n",
      " |      >>> y = np.zeros((2, 3, 4))\n",
      " |      >>> y.ndim\n",
      " |      3\n",
      " |  \n",
      " |  real\n",
      " |      The real part of the array.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.sqrt([1+0j, 0+1j])\n",
      " |      >>> x.real\n",
      " |      array([ 1.        ,  0.70710678])\n",
      " |      >>> x.real.dtype\n",
      " |      dtype('float64')\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.real : equivalent function\n",
      " |  \n",
      " |  shape\n",
      " |      Tuple of array dimensions.\n",
      " |      \n",
      " |      The shape property is usually used to get the current shape of an array,\n",
      " |      but may also be used to reshape the array in-place by assigning a tuple of\n",
      " |      array dimensions to it.  As with `numpy.reshape`, one of the new shape\n",
      " |      dimensions can be -1, in which case its value is inferred from the size of\n",
      " |      the array and the remaining dimensions. Reshaping an array in-place will\n",
      " |      fail if a copy is required.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.array([1, 2, 3, 4])\n",
      " |      >>> x.shape\n",
      " |      (4,)\n",
      " |      >>> y = np.zeros((2, 3, 4))\n",
      " |      >>> y.shape\n",
      " |      (2, 3, 4)\n",
      " |      >>> y.shape = (3, 8)\n",
      " |      >>> y\n",
      " |      array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
      " |             [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
      " |             [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])\n",
      " |      >>> y.shape = (3, 6)\n",
      " |      Traceback (most recent call last):\n",
      " |        File \"<stdin>\", line 1, in <module>\n",
      " |      ValueError: total size of new array must be unchanged\n",
      " |      >>> np.zeros((4,2))[::2].shape = (-1,)\n",
      " |      Traceback (most recent call last):\n",
      " |        File \"<stdin>\", line 1, in <module>\n",
      " |      AttributeError: incompatible shape for a non-contiguous array\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.reshape : similar function\n",
      " |      ndarray.reshape : similar method\n",
      " |  \n",
      " |  size\n",
      " |      Number of elements in the array.\n",
      " |      \n",
      " |      Equivalent to ``np.prod(a.shape)``, i.e., the product of the array's\n",
      " |      dimensions.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.zeros((3, 5, 2), dtype=np.complex128)\n",
      " |      >>> x.size\n",
      " |      30\n",
      " |      >>> np.prod(x.shape)\n",
      " |      30\n",
      " |  \n",
      " |  strides\n",
      " |      Tuple of bytes to step in each dimension when traversing an array.\n",
      " |      \n",
      " |      The byte offset of element ``(i[0], i[1], ..., i[n])`` in an array `a`\n",
      " |      is::\n",
      " |      \n",
      " |          offset = sum(np.array(i) * a.strides)\n",
      " |      \n",
      " |      A more detailed explanation of strides can be found in the\n",
      " |      \"ndarray.rst\" file in the NumPy reference guide.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Imagine an array of 32-bit integers (each 4 bytes)::\n",
      " |      \n",
      " |        x = np.array([[0, 1, 2, 3, 4],\n",
      " |                      [5, 6, 7, 8, 9]], dtype=np.int32)\n",
      " |      \n",
      " |      This array is stored in memory as 40 bytes, one after the other\n",
      " |      (known as a contiguous block of memory).  The strides of an array tell\n",
      " |      us how many bytes we have to skip in memory to move to the next position\n",
      " |      along a certain axis.  For example, we have to skip 4 bytes (1 value) to\n",
      " |      move to the next column, but 20 bytes (5 values) to get to the same\n",
      " |      position in the next row.  As such, the strides for the array `x` will be\n",
      " |      ``(20, 4)``.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.lib.stride_tricks.as_strided\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> y = np.reshape(np.arange(2*3*4), (2,3,4))\n",
      " |      >>> y\n",
      " |      array([[[ 0,  1,  2,  3],\n",
      " |              [ 4,  5,  6,  7],\n",
      " |              [ 8,  9, 10, 11]],\n",
      " |             [[12, 13, 14, 15],\n",
      " |              [16, 17, 18, 19],\n",
      " |              [20, 21, 22, 23]]])\n",
      " |      >>> y.strides\n",
      " |      (48, 16, 4)\n",
      " |      >>> y[1,1,1]\n",
      " |      17\n",
      " |      >>> offset=sum(y.strides * np.array((1,1,1)))\n",
      " |      >>> offset/y.itemsize\n",
      " |      17\n",
      " |      \n",
      " |      >>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0)\n",
      " |      >>> x.strides\n",
      " |      (32, 4, 224, 1344)\n",
      " |      >>> i = np.array([3,5,2,2])\n",
      " |      >>> offset = sum(i * x.strides)\n",
      " |      >>> x[3,5,2,2]\n",
      " |      813\n",
      " |      >>> offset / x.itemsize\n",
      " |      813\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 查看维度\n",
    "print(array1.ndim)\n",
    "print(array2.ndim)\n",
    "print(array3.ndim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10,)\n",
      "(2, 10)\n",
      "(2, 3, 3)\n"
     ]
    }
   ],
   "source": [
    "# 数组的形状，Tuple类型\n",
    "print(array1.shape)\n",
    "print(array2.shape) # 2行10列\n",
    "print(array3.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看总共多少元素（行*列）\n",
    "array2.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int64')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看元素的数据类型\n",
    "array2.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 扩展部分 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 2., 3.],\n",
       "       [4., 5., 6.]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Array元素类型都一致，如果不一致会以最大兼容来初始化\n",
    "\n",
    "np.array([[1,2,3],[4,5,6.0]]) # 都变成Float类型了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 2., 3.],\n",
       "       [4., 5., 6.]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 指定类型\n",
    "np.array([[1,2,3],[4,5,6]],dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1], [1, 2]]\n",
      "[list([1]) list([1, 2])]\n",
      "object\n"
     ]
    }
   ],
   "source": [
    "# 行元素的个数不一致的测试\n",
    "\n",
    "test_list = [[1],[1,2]]\n",
    "print(test_list)\n",
    "\n",
    "test_array = np.array(test_list)\n",
    "\n",
    "print(test_array)\n",
    "\n",
    "print(test_array.dtype) # 全部变成了object"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.通过arange和reshape创建数组\n",
    "\n",
    "`range()`返回的是`range`对象，而 **`np.arange()`返回的是`numpy.ndarray() `**\n",
    "\n",
    "两者都可以进行迭代，而`np.nrange`还是一个序列，可被当做向量使用\n",
    "\n",
    "`range()`不支持步长为小数, **`np.arange()`支持步长为小数**\n",
    "\n",
    "如果这些基础类型还不是很清楚，可以看我之前写的文章：<a href=\"https://www.cnblogs.com/dunitian/p/4822808.html#ai\" target=\"_blank\">https://www.cnblogs.com/dotnetcrazy/p/9155310.html</a>\n",
    "\n",
    "---\n",
    "\n",
    "**多维数组创建**：（reshape的 **行x列 != 元素个数** 就会报错）\n",
    "\n",
    "创建3行5列的数组：`np.arange(15).reshape((3,5))`\n",
    "\n",
    "告诉它多少列，自动求行：`np.arange(20).reshape((-1,5))`\n",
    "\n",
    "告诉它多少行，自动求列：`np.arange(20).reshape((4,-1))`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function arange in module numpy.core.multiarray:\n",
      "\n",
      "arange(...)\n",
      "    arange([start,] stop[, step,], dtype=None)\n",
      "    \n",
      "    Return evenly spaced values within a given interval.\n",
      "    \n",
      "    Values are generated within the half-open interval ``[start, stop)``\n",
      "    (in other words, the interval including `start` but excluding `stop`).\n",
      "    For integer arguments the function is equivalent to the Python built-in\n",
      "    `range <http://docs.python.org/lib/built-in-funcs.html>`_ function,\n",
      "    but returns an ndarray rather than a list.\n",
      "    \n",
      "    When using a non-integer step, such as 0.1, the results will often not\n",
      "    be consistent.  It is better to use ``linspace`` for these cases.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    start : number, optional\n",
      "        Start of interval.  The interval includes this value.  The default\n",
      "        start value is 0.\n",
      "    stop : number\n",
      "        End of interval.  The interval does not include this value, except\n",
      "        in some cases where `step` is not an integer and floating point\n",
      "        round-off affects the length of `out`.\n",
      "    step : number, optional\n",
      "        Spacing between values.  For any output `out`, this is the distance\n",
      "        between two adjacent values, ``out[i+1] - out[i]``.  The default\n",
      "        step size is 1.  If `step` is specified as a position argument,\n",
      "        `start` must also be given.\n",
      "    dtype : dtype\n",
      "        The type of the output array.  If `dtype` is not given, infer the data\n",
      "        type from the other input arguments.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    arange : ndarray\n",
      "        Array of evenly spaced values.\n",
      "    \n",
      "        For floating point arguments, the length of the result is\n",
      "        ``ceil((stop - start)/step)``.  Because of floating point overflow,\n",
      "        this rule may result in the last element of `out` being greater\n",
      "        than `stop`.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    linspace : Evenly spaced numbers with careful handling of endpoints.\n",
      "    ogrid: Arrays of evenly spaced numbers in N-dimensions.\n",
      "    mgrid: Grid-shaped arrays of evenly spaced numbers in N-dimensions.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.arange(3)\n",
      "    array([0, 1, 2])\n",
      "    >>> np.arange(3.0)\n",
      "    array([ 0.,  1.,  2.])\n",
      "    >>> np.arange(3,7)\n",
      "    array([3, 4, 5, 6])\n",
      "    >>> np.arange(3,7,2)\n",
      "    array([3, 5])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.arange)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(range(1,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用法和range差不多\n",
    "array1 = np.arange(1,10) # [1,10)\n",
    "\n",
    "print(array1)\n",
    "\n",
    "type(array1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3 4 5 6 7 8 9 "
     ]
    }
   ],
   "source": [
    "# 可以直接迭代\n",
    "for i in array1:\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'float' object cannot be interpreted as an integer",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-27-546bf1d2fbc2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# Python里面的range不支持步长为小数\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0.5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'float' object cannot be interpreted as an integer"
     ]
    }
   ],
   "source": [
    "# Python里面的range不支持步长为小数\n",
    "range(1,10,0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. , 5.5, 6. , 6.5, 7. ,\n",
       "       7.5, 8. , 8.5, 9. , 9.5])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 支持步长为小数\n",
    "np.arange(1,10,0.5) # step为0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 开始变化 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function reshape:\n",
      "\n",
      "reshape(...) method of numpy.ndarray instance\n",
      "    a.reshape(shape, order='C')\n",
      "    \n",
      "    Returns an array containing the same data with a new shape.\n",
      "    \n",
      "    Refer to `numpy.reshape` for full documentation.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    numpy.reshape : equivalent function\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    Unlike the free function `numpy.reshape`, this method on `ndarray` allows\n",
      "    the elements of the shape parameter to be passed in as separate arguments.\n",
      "    For example, ``a.reshape(10, 11)`` is equivalent to\n",
      "    ``a.reshape((10, 11))``.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(array1.reshape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. ],\n",
       "       [5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. , 9.5]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建2维数组，参数传元组比较合适（官方案例也是元组）\n",
    "np.arange(1,10,0.5).reshape((2,9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3行5列\n",
    "np.arange(15).reshape((3,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 告诉它多少列，自动求行\n",
    "np.arange(20).reshape((-1,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 告诉它多少行，自动求列\n",
    "np.arange(20).reshape((4,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "cannot reshape array of size 20 into shape (3,7)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-35-7050b8704de5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# reshape的 **行x列 != 元素个数** 就会报错\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m7\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m: cannot reshape array of size 20 into shape (3,7)"
     ]
    }
   ],
   "source": [
    "# reshape的 **行x列 != 元素个数** 就会报错\n",
    "np.arange(20).reshape(3,7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.4.创建随机数组\n",
    "\n",
    "`np.random.randint` 生成给定范围内均匀分布的整数\n",
    "\n",
    "`np.random.rand` 生成`[0,1)`之间均匀分布的随机数\n",
    "\n",
    "`np.random.ranf` 生成均匀分布的浮点数字`[0.0, 1.0)`\n",
    "\n",
    "`np.random.randn` 生成符合正态分布的随机数 \n",
    "\n",
    "`np.random.normal` 从正态分布中返回符合你输入的均值与方差以及shape的值\n",
    "\n",
    "扩展：`np.random.seed` 设置随机种子，一般不太用，特殊场景需要"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成一个给定范围内均匀分布的整数[0,10)\n",
    "np.random.randint(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 6, 5, 2, 1, 6, 0, 1, 9, 3, 8, 9, 1, 0, 0, 5, 7, 2, 2, 7])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成20个在[0,10)的整数\n",
    "np.random.randint(10,size=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 0, 4],\n",
       "       [4, 1, 4, 1]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成2*4的数组，取值范围在[0,5)\n",
    "np.random.randint(5, size=(2, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function randint:\n",
      "\n",
      "randint(...) method of mtrand.RandomState instance\n",
      "    randint(low, high=None, size=None, dtype='l')\n",
      "    \n",
      "    Return random integers from `low` (inclusive) to `high` (exclusive).\n",
      "    \n",
      "    Return random integers from the \"discrete uniform\" distribution of\n",
      "    the specified dtype in the \"half-open\" interval [`low`, `high`). If\n",
      "    `high` is None (the default), then results are from [0, `low`).\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    low : int\n",
      "        Lowest (signed) integer to be drawn from the distribution (unless\n",
      "        ``high=None``, in which case this parameter is one above the\n",
      "        *highest* such integer).\n",
      "    high : int, optional\n",
      "        If provided, one above the largest (signed) integer to be drawn\n",
      "        from the distribution (see above for behavior if ``high=None``).\n",
      "    size : int or tuple of ints, optional\n",
      "        Output shape.  If the given shape is, e.g., ``(m, n, k)``, then\n",
      "        ``m * n * k`` samples are drawn.  Default is None, in which case a\n",
      "        single value is returned.\n",
      "    dtype : dtype, optional\n",
      "        Desired dtype of the result. All dtypes are determined by their\n",
      "        name, i.e., 'int64', 'int', etc, so byteorder is not available\n",
      "        and a specific precision may have different C types depending\n",
      "        on the platform. The default value is 'np.int'.\n",
      "    \n",
      "        .. versionadded:: 1.11.0\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : int or ndarray of ints\n",
      "        `size`-shaped array of random integers from the appropriate\n",
      "        distribution, or a single such random int if `size` not provided.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    random.random_integers : similar to `randint`, only for the closed\n",
      "        interval [`low`, `high`], and 1 is the lowest value if `high` is\n",
      "        omitted. In particular, this other one is the one to use to generate\n",
      "        uniformly distributed discrete non-integers.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.random.randint(2, size=10)\n",
      "    array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])\n",
      "    >>> np.random.randint(1, size=10)\n",
      "    array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n",
      "    \n",
      "    Generate a 2 x 4 array of ints between 0 and 4, inclusive:\n",
      "    \n",
      "    >>> np.random.randint(5, size=(2, 4))\n",
      "    array([[4, 0, 2, 1],\n",
      "           [3, 2, 2, 0]])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 更多可以查看\n",
    "help(np.random.randint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.93052782, 0.52355788, 0.60162643, 0.57750512, 0.32934868,\n",
       "       0.04529727, 0.1089536 , 0.98409213, 0.72327059, 0.93003607])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 均匀分布的随机数[0,1)\n",
    "np.random.rand(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function rand:\n",
      "\n",
      "rand(...) method of mtrand.RandomState instance\n",
      "    rand(d0, d1, ..., dn)\n",
      "    \n",
      "    Random values in a given shape.\n",
      "    \n",
      "    Create an array of the given shape and populate it with\n",
      "    random samples from a uniform distribution\n",
      "    over ``[0, 1)``.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    d0, d1, ..., dn : int, optional\n",
      "        The dimensions of the returned array, should all be positive.\n",
      "        If no argument is given a single Python float is returned.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : ndarray, shape ``(d0, d1, ..., dn)``\n",
      "        Random values.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    random\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    This is a convenience function. If you want an interface that\n",
      "    takes a shape-tuple as the first argument, refer to\n",
      "    np.random.random_sample .\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.random.rand(3,2)\n",
      "    array([[ 0.14022471,  0.96360618],  #random\n",
      "           [ 0.37601032,  0.25528411],  #random\n",
      "           [ 0.49313049,  0.94909878]]) #random\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 更多可以查看\n",
    "help(np.random.rand)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.02181866, 0.87750098, 0.19618116, 0.5076408 , 0.86583221,\n",
       "       0.56368598, 0.69047121, 0.97234975, 0.13002229, 0.38533132])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 均匀分布的浮点数字[0.0, 1.0)\n",
    "np.random.ranf(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random_sample:\n",
      "\n",
      "random_sample(...) method of mtrand.RandomState instance\n",
      "    random_sample(size=None)\n",
      "    \n",
      "    Return random floats in the half-open interval [0.0, 1.0).\n",
      "    \n",
      "    Results are from the \"continuous uniform\" distribution over the\n",
      "    stated interval.  To sample :math:`Unif[a, b), b > a` multiply\n",
      "    the output of `random_sample` by `(b-a)` and add `a`::\n",
      "    \n",
      "      (b - a) * random_sample() + a\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    size : int or tuple of ints, optional\n",
      "        Output shape.  If the given shape is, e.g., ``(m, n, k)``, then\n",
      "        ``m * n * k`` samples are drawn.  Default is None, in which case a\n",
      "        single value is returned.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : float or ndarray of floats\n",
      "        Array of random floats of shape `size` (unless ``size=None``, in which\n",
      "        case a single float is returned).\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.random.random_sample()\n",
      "    0.47108547995356098\n",
      "    >>> type(np.random.random_sample())\n",
      "    <type 'float'>\n",
      "    >>> np.random.random_sample((5,))\n",
      "    array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428])\n",
      "    \n",
      "    Three-by-two array of random numbers from [-5, 0):\n",
      "    \n",
      "    >>> 5 * np.random.random_sample((3, 2)) - 5\n",
      "    array([[-3.99149989, -0.52338984],\n",
      "           [-2.99091858, -0.79479508],\n",
      "           [-1.23204345, -1.75224494]])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 更多可以查看\n",
    "help(np.random.ranf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.25448705, -1.33181234, -0.51123031, -2.12012698,  0.52889404,\n",
       "        0.76552993,  0.86535772,  0.05172692,  0.42584787,  0.56117651])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建10个符合正态分布的随机数\n",
    "np.random.randn(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function randn:\n",
      "\n",
      "randn(...) method of mtrand.RandomState instance\n",
      "    randn(d0, d1, ..., dn)\n",
      "    \n",
      "    Return a sample (or samples) from the \"standard normal\" distribution.\n",
      "    \n",
      "    If positive, int_like or int-convertible arguments are provided,\n",
      "    `randn` generates an array of shape ``(d0, d1, ..., dn)``, filled\n",
      "    with random floats sampled from a univariate \"normal\" (Gaussian)\n",
      "    distribution of mean 0 and variance 1 (if any of the :math:`d_i` are\n",
      "    floats, they are first converted to integers by truncation). A single\n",
      "    float randomly sampled from the distribution is returned if no\n",
      "    argument is provided.\n",
      "    \n",
      "    This is a convenience function.  If you want an interface that takes a\n",
      "    tuple as the first argument, use `numpy.random.standard_normal` instead.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    d0, d1, ..., dn : int, optional\n",
      "        The dimensions of the returned array, should be all positive.\n",
      "        If no argument is given a single Python float is returned.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    Z : ndarray or float\n",
      "        A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from\n",
      "        the standard normal distribution, or a single such float if\n",
      "        no parameters were supplied.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    random.standard_normal : Similar, but takes a tuple as its argument.\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    For random samples from :math:`N(\\mu, \\sigma^2)`, use:\n",
      "    \n",
      "    ``sigma * np.random.randn(...) + mu``\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.random.randn()\n",
      "    2.1923875335537315 #random\n",
      "    \n",
      "    Two-by-four array of samples from N(3, 6.25):\n",
      "    \n",
      "    >>> 2.5 * np.random.randn(2, 4) + 3\n",
      "    array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random\n",
      "           [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 更多可以查看\n",
    "help(np.random.randn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5187472471641197"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 符合均值为0，方差为1的正态分布的浮点数\n",
    "np.random.normal()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-87.6264354067521"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 符合均值为10，方差为100的正态分布的浮点数\n",
    "np.random.normal(10,100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2.03119172e+02, -9.21914693e+01],\n",
       "       [-1.29009041e+02, -6.62820766e-02],\n",
       "       [-8.53437355e+01,  7.79160227e+01]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 符合均值为10，方差为100，3*2的正态分布矩阵\n",
    "np.random.normal(10,100,(3,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function normal:\n",
      "\n",
      "normal(...) method of mtrand.RandomState instance\n",
      "    normal(loc=0.0, scale=1.0, size=None)\n",
      "    \n",
      "    Draw random samples from a normal (Gaussian) distribution.\n",
      "    \n",
      "    The probability density function of the normal distribution, first\n",
      "    derived by De Moivre and 200 years later by both Gauss and Laplace\n",
      "    independently [2]_, is often called the bell curve because of\n",
      "    its characteristic shape (see the example below).\n",
      "    \n",
      "    The normal distributions occurs often in nature.  For example, it\n",
      "    describes the commonly occurring distribution of samples influenced\n",
      "    by a large number of tiny, random disturbances, each with its own\n",
      "    unique distribution [2]_.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    loc : float or array_like of floats\n",
      "        Mean (\"centre\") of the distribution.\n",
      "    scale : float or array_like of floats\n",
      "        Standard deviation (spread or \"width\") of the distribution.\n",
      "    size : int or tuple of ints, optional\n",
      "        Output shape.  If the given shape is, e.g., ``(m, n, k)``, then\n",
      "        ``m * n * k`` samples are drawn.  If size is ``None`` (default),\n",
      "        a single value is returned if ``loc`` and ``scale`` are both scalars.\n",
      "        Otherwise, ``np.broadcast(loc, scale).size`` samples are drawn.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    out : ndarray or scalar\n",
      "        Drawn samples from the parameterized normal distribution.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    scipy.stats.norm : probability density function, distribution or\n",
      "        cumulative density function, etc.\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    The probability density for the Gaussian distribution is\n",
      "    \n",
      "    .. math:: p(x) = \\frac{1}{\\sqrt{ 2 \\pi \\sigma^2 }}\n",
      "                     e^{ - \\frac{ (x - \\mu)^2 } {2 \\sigma^2} },\n",
      "    \n",
      "    where :math:`\\mu` is the mean and :math:`\\sigma` the standard\n",
      "    deviation. The square of the standard deviation, :math:`\\sigma^2`,\n",
      "    is called the variance.\n",
      "    \n",
      "    The function has its peak at the mean, and its \"spread\" increases with\n",
      "    the standard deviation (the function reaches 0.607 times its maximum at\n",
      "    :math:`x + \\sigma` and :math:`x - \\sigma` [2]_).  This implies that\n",
      "    `numpy.random.normal` is more likely to return samples lying close to\n",
      "    the mean, rather than those far away.\n",
      "    \n",
      "    References\n",
      "    ----------\n",
      "    .. [1] Wikipedia, \"Normal distribution\",\n",
      "           http://en.wikipedia.org/wiki/Normal_distribution\n",
      "    .. [2] P. R. Peebles Jr., \"Central Limit Theorem\" in \"Probability,\n",
      "           Random Variables and Random Signal Principles\", 4th ed., 2001,\n",
      "           pp. 51, 51, 125.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    Draw samples from the distribution:\n",
      "    \n",
      "    >>> mu, sigma = 0, 0.1 # mean and standard deviation\n",
      "    >>> s = np.random.normal(mu, sigma, 1000)\n",
      "    \n",
      "    Verify the mean and the variance:\n",
      "    \n",
      "    >>> abs(mu - np.mean(s)) < 0.01\n",
      "    True\n",
      "    \n",
      "    >>> abs(sigma - np.std(s, ddof=1)) < 0.01\n",
      "    True\n",
      "    \n",
      "    Display the histogram of the samples, along with\n",
      "    the probability density function:\n",
      "    \n",
      "    >>> import matplotlib.pyplot as plt\n",
      "    >>> count, bins, ignored = plt.hist(s, 30, normed=True)\n",
      "    >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *\n",
      "    ...                np.exp( - (bins - mu)**2 / (2 * sigma**2) ),\n",
      "    ...          linewidth=2, color='r')\n",
      "    >>> plt.show()\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 更多可以查看\n",
    "help(np.random.normal)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.5.linspace创建等差数组\n",
    "\n",
    "`np.linspace` 生成等差数列的数组\n",
    "\n",
    "和arange不一样的是end值可以取到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function linspace in module numpy.core.function_base:\n",
      "\n",
      "linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)\n",
      "    Return evenly spaced numbers over a specified interval.\n",
      "    \n",
      "    Returns `num` evenly spaced samples, calculated over the\n",
      "    interval [`start`, `stop`].\n",
      "    \n",
      "    The endpoint of the interval can optionally be excluded.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    start : scalar\n",
      "        The starting value of the sequence.\n",
      "    stop : scalar\n",
      "        The end value of the sequence, unless `endpoint` is set to False.\n",
      "        In that case, the sequence consists of all but the last of ``num + 1``\n",
      "        evenly spaced samples, so that `stop` is excluded.  Note that the step\n",
      "        size changes when `endpoint` is False.\n",
      "    num : int, optional\n",
      "        Number of samples to generate. Default is 50. Must be non-negative.\n",
      "    endpoint : bool, optional\n",
      "        If True, `stop` is the last sample. Otherwise, it is not included.\n",
      "        Default is True.\n",
      "    retstep : bool, optional\n",
      "        If True, return (`samples`, `step`), where `step` is the spacing\n",
      "        between samples.\n",
      "    dtype : dtype, optional\n",
      "        The type of the output array.  If `dtype` is not given, infer the data\n",
      "        type from the other input arguments.\n",
      "    \n",
      "        .. versionadded:: 1.9.0\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    samples : ndarray\n",
      "        There are `num` equally spaced samples in the closed interval\n",
      "        ``[start, stop]`` or the half-open interval ``[start, stop)``\n",
      "        (depending on whether `endpoint` is True or False).\n",
      "    step : float, optional\n",
      "        Only returned if `retstep` is True\n",
      "    \n",
      "        Size of spacing between samples.\n",
      "    \n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    arange : Similar to `linspace`, but uses a step size (instead of the\n",
      "             number of samples).\n",
      "    logspace : Samples uniformly distributed in log space.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.linspace(2.0, 3.0, num=5)\n",
      "    array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ])\n",
      "    >>> np.linspace(2.0, 3.0, num=5, endpoint=False)\n",
      "    array([ 2. ,  2.2,  2.4,  2.6,  2.8])\n",
      "    >>> np.linspace(2.0, 3.0, num=5, retstep=True)\n",
      "    (array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)\n",
      "    \n",
      "    Graphical illustration:\n",
      "    \n",
      "    >>> import matplotlib.pyplot as plt\n",
      "    >>> N = 8\n",
      "    >>> y = np.zeros(N)\n",
      "    >>> x1 = np.linspace(0, 10, N, endpoint=True)\n",
      "    >>> x2 = np.linspace(0, 10, N, endpoint=False)\n",
      "    >>> plt.plot(x1, y, 'o')\n",
      "    [<matplotlib.lines.Line2D object at 0x...>]\n",
      "    >>> plt.plot(x2, y + 0.5, 'o')\n",
      "    [<matplotlib.lines.Line2D object at 0x...>]\n",
      "    >>> plt.ylim([-0.5, 1])\n",
      "    (-0.5, 1)\n",
      "    >>> plt.show()\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.linspace)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个从0~10，差值为1的等差数组\n",
    "# 0~10总共11个数（和arange不一样的是end值可以取到）\n",
    "np.linspace(0,10,11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  2.,  4.,  6.,  8., 10., 12., 14., 16., 18., 20.])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 0~20(总共22个数)差值为2的等差数组\n",
    "np.linspace(0,20,11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  2.,  4.,  6.,  8., 10., 12., 14., 16., 18.])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以让end_index取不到\n",
    "np.linspace(0,20,10,endpoint=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.数组常用方法\n",
    "\n",
    "### 2.1.数组元素的获取\n",
    "\n",
    "基础用法之前讲过，可以回顾一下：<a href=\"https://www.cnblogs.com/dotnetcrazy/p/9114691.html#2.1.Python\" target=\"_blank\">https://www.cnblogs.com/dotnetcrazy/p/9114691.html#2.1.Python</a>\n",
    "\n",
    "简写：**`array_name[行,列]`** （行列都是从0开始）\n",
    "\n",
    "其他写法：`array_name[行][列]`（**Numpy不建议这么写，多维数组用切片的时候语义容易偏差**，eg:`xx[:2][:2]`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "# 先用熟悉的一维数组\n",
    "array1 = np.arange(10)\n",
    "\n",
    "print(array1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取第一个元素\n",
    "array1[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取最后一个元素\n",
    "array1[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取第二个元素\n",
    "array1[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取倒数第二个元素\n",
    "array1[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 二维数组 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "source": [
    "test_array = np.array([[1,2,3],[4,5,6]])\n",
    "\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取元素4（行列都是从0开始）\n",
    "test_array[1][0] # Numpy不建议这么写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取元素4 简写\n",
    "test_array[1,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取第一行最后一个\n",
    "test_array[0,-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取最后一行倒数第二个元素\n",
    "test_array[-1,-2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2.多维数组的切片用法\n",
    "\n",
    "**`array_name[行切片,列切片]`** eg：`test_array[1:3,1:3]`==> 取索引为1,2的行；取索引为1,2的列\n",
    "\n",
    "基础用法之前讲过，可以回顾一下：<a href=\"https://www.cnblogs.com/dotnetcrazy/p/9155310.html#1.7.列表切片\" target=\"_blank\">https://www.cnblogs.com/dotnetcrazy/p/9155310.html#1.7.列表切片</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n",
      " 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47\n",
      " 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71\n",
      " 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95\n",
      " 96 97 98 99]\n"
     ]
    }
   ],
   "source": [
    "# 先用熟悉的一维数组\n",
    "array1 = np.arange(100)\n",
    "\n",
    "print(array1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,\n",
       "       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
       "       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,\n",
       "       51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,\n",
       "       68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,\n",
       "       85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 全部取出来\n",
    "array1[::]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,\n",
       "       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,\n",
       "       35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n",
       "       52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,\n",
       "       69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,\n",
       "       86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从索引为1～最后\n",
    "array1[1::]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 切片开始 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 11, 21, 31, 41, 51, 61, 71, 81, 91])"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从第二个元素取到最后,step为10\n",
    "array1[1::10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [1,5) 从下标1取到下标4,下标为5的取不到\n",
    "array1[1:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,\n",
       "       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,\n",
       "       35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n",
       "       52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,\n",
       "       69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,\n",
       "       86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取下标为1～倒数第二个元素（end_index取不到）\n",
    "array1[1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取前10个\n",
    "array1[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取最后10个，可以理解为从索引-5的元素到最后\n",
    "array1[-10:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 前11~20（eg：第二页）\n",
    "array1[10:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([80, 81, 82, 83, 84, 85, 86, 87, 88, 89])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取80~90（eg:倒数第二页）\n",
    "array1[-20:-10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 前20个数，每两个取一个（eg:隔行换样式）\n",
    "array1[:20:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有数每10个取一个（eg:test的时候十里挑一）\n",
    "array1[::10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 二维数组 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n"
     ]
    }
   ],
   "source": [
    "# 生成一个多维数组\n",
    "test_array = np.arange(15).reshape(3,5)\n",
    "\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 7,  8,  9],\n",
       "       [12, 13, 14]])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [行切片，列切片]\n",
    "# 行：取第2行到最后，列：取第3列到最后\n",
    "test_array[1:,2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 4],\n",
       "       [ 9],\n",
       "       [14]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有行，最后一列\n",
    "test_array[:,-1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 5,  6],\n",
       "       [10, 11]])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有行，索引[0,2)列\n",
    "test_array[:,:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6]])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 索引1的行，索引1的列\n",
    "test_array[1:2,1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "# 上面的等同于test_array[1][1]\n",
    "print(test_array[1,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6,  7],\n",
       "       [11, 12]])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取索引为1,2的行；取索引为1,2的列\n",
    "test_array[1:3,1:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.unique、max、min、sum\n",
    "\n",
    "`np.unique` 找出其中不重复的元素\n",
    "\n",
    "`np.max` 找出其中最大的值\n",
    "\n",
    "`np.min` 找出其中最小值\n",
    "\n",
    "`np.sum` 求和系列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 4 3 4 2]\n",
      " [1 0 1 1 3]\n",
      " [2 0 4 4 0]\n",
      " [3 3 1 0 3]]\n"
     ]
    }
   ],
   "source": [
    "a = np.random.randint(5,size=(4,5))\n",
    "\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出其中不重复的元素\n",
    "np.unique(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出其中最大的值\n",
    "np.max(a) # 或者：a.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出第1行最大值\n",
    "np.max(a[0]) # 或者：max(a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出第3列最大值\n",
    "np.max(a[:,2]) # 或者：max(a[:,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 4 3 4 2]\n",
      " [1 0 1 1 3]\n",
      " [2 0 4 4 0]\n",
      " [3 3 1 0 3]]\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出其中最小值\n",
    "np.min(a) # a.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出第1行最小值\n",
    "np.min(a[0]) # min(a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 找出第3列最小值\n",
    "np.min(a[:,2]) # min(a[:,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 4 3 4 2]\n",
      " [1 0 1 1 3]\n",
      " [2 0 4 4 0]\n",
      " [3 3 1 0 3]]\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "40"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([7, 7, 9, 9, 8])"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 注意：这个是每一列分别求和\n",
    "sum(a) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([14,  6, 10, 10])"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 每一行\n",
    "np.sum(a,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([7, 7, 9, 9, 8])"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 每一列\n",
    "np.sum(a,axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求第1行和\n",
    "np.sum(a[0]) # sum(a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求第3列和\n",
    "np.sum(a[:,2]) # sum(a[:,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "######### 扩展部分有两种写法的性能对比 #########"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.4.load导入、save导出\n",
    "\n",
    "以前我们可能使用 pickle来实现，现在直接可以用自带的方法实现，eg：\n",
    "```py\n",
    "import pickle\n",
    "\n",
    "f = open('x.dat','wb') # 写二进制文件\n",
    "pickle.dump(array2,f) # 把对象array2写入f中\n",
    "f.close()\n",
    "\n",
    "f = open('x.dat','rb') # 读二进制文件\n",
    "temp = pickle.load(f)\n",
    "print(temp)\n",
    "```\n",
    "现在直接调用Numpy里面的方法即可\n",
    "```py\n",
    "np.save('file_name',obj)\n",
    "np.load('file_name.npy')\n",
    "```\n",
    "多个文件：推荐用这种指定key的方式 默认以npz结尾:\n",
    "```py\n",
    "np.savez('file_name',obj1=obj1,obj2=obj2)\n",
    "temp = np.load('file_name.npz')\n",
    "temp[obj1]\n",
    "temp.close()\n",
    "```\n",
    "也可以用扩展里面的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function save in module numpy.lib.npyio:\n",
      "\n",
      "save(file, arr, allow_pickle=True, fix_imports=True)\n",
      "    Save an array to a binary file in NumPy ``.npy`` format.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    file : file, str, or pathlib.Path\n",
      "        File or filename to which the data is saved.  If file is a file-object,\n",
      "        then the filename is unchanged.  If file is a string or Path, a ``.npy``\n",
      "        extension will be appended to the file name if it does not already\n",
      "        have one.\n",
      "    arr : array_like\n",
      "        Array data to be saved.\n",
      "    allow_pickle : bool, optional\n",
      "        Allow saving object arrays using Python pickles. Reasons for disallowing\n",
      "        pickles include security (loading pickled data can execute arbitrary\n",
      "        code) and portability (pickled objects may not be loadable on different\n",
      "        Python installations, for example if the stored objects require libraries\n",
      "        that are not available, and not all pickled data is compatible between\n",
      "        Python 2 and Python 3).\n",
      "        Default: True\n",
      "    fix_imports : bool, optional\n",
      "        Only useful in forcing objects in object arrays on Python 3 to be\n",
      "        pickled in a Python 2 compatible way. If `fix_imports` is True, pickle\n",
      "        will try to map the new Python 3 names to the old module names used in\n",
      "        Python 2, so that the pickle data stream is readable with Python 2.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    savez : Save several arrays into a ``.npz`` archive\n",
      "    savetxt, load\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    For a description of the ``.npy`` format, see the module docstring\n",
      "    of `numpy.lib.format` or the NumPy Enhancement Proposal\n",
      "    http://docs.scipy.org/doc/numpy/neps/npy-format.html\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> from tempfile import TemporaryFile\n",
      "    >>> outfile = TemporaryFile()\n",
      "    \n",
      "    >>> x = np.arange(10)\n",
      "    >>> np.save(outfile, x)\n",
      "    \n",
      "    >>> outfile.seek(0) # Only needed here to simulate closing & reopening file\n",
      "    >>> np.load(outfile)\n",
      "    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.save)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NumpyBase.ipynb  矩阵系列.ipynb\n",
      "[[0 1 2 3 4 5 6 7 8 9]\n",
      " [0 1 2 3 4 5 6 7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "!ls # 查看下当前目录\n",
    "\n",
    "print(array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把array2对象保存成本地二进制文件（自动以.npy结尾）\n",
    "np.save('bak',array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bak.npy  NumpyBase.ipynb  矩阵系列.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
       "       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取\n",
    "np.load('bak.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 多个对象保存 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function savez in module numpy.lib.npyio:\n",
      "\n",
      "savez(file, *args, **kwds)\n",
      "    Save several arrays into a single file in uncompressed ``.npz`` format.\n",
      "    \n",
      "    If arguments are passed in with no keywords, the corresponding variable\n",
      "    names, in the ``.npz`` file, are 'arr_0', 'arr_1', etc. If keyword\n",
      "    arguments are given, the corresponding variable names, in the ``.npz``\n",
      "    file will match the keyword names.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    file : str or file\n",
      "        Either the file name (string) or an open file (file-like object)\n",
      "        where the data will be saved. If file is a string or a Path, the\n",
      "        ``.npz`` extension will be appended to the file name if it is not\n",
      "        already there.\n",
      "    args : Arguments, optional\n",
      "        Arrays to save to the file. Since it is not possible for Python to\n",
      "        know the names of the arrays outside `savez`, the arrays will be saved\n",
      "        with names \"arr_0\", \"arr_1\", and so on. These arguments can be any\n",
      "        expression.\n",
      "    kwds : Keyword arguments, optional\n",
      "        Arrays to save to the file. Arrays will be saved in the file with the\n",
      "        keyword names.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    None\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    save : Save a single array to a binary file in NumPy format.\n",
      "    savetxt : Save an array to a file as plain text.\n",
      "    savez_compressed : Save several arrays into a compressed ``.npz`` archive\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    The ``.npz`` file format is a zipped archive of files named after the\n",
      "    variables they contain.  The archive is not compressed and each file\n",
      "    in the archive contains one variable in ``.npy`` format. For a\n",
      "    description of the ``.npy`` format, see `numpy.lib.format` or the\n",
      "    NumPy Enhancement Proposal\n",
      "    http://docs.scipy.org/doc/numpy/neps/npy-format.html\n",
      "    \n",
      "    When opening the saved ``.npz`` file with `load` a `NpzFile` object is\n",
      "    returned. This is a dictionary-like object which can be queried for\n",
      "    its list of arrays (with the ``.files`` attribute), and for the arrays\n",
      "    themselves.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> from tempfile import TemporaryFile\n",
      "    >>> outfile = TemporaryFile()\n",
      "    >>> x = np.arange(10)\n",
      "    >>> y = np.sin(x)\n",
      "    \n",
      "    Using `savez` with \\*args, the arrays are saved with default names.\n",
      "    \n",
      "    >>> np.savez(outfile, x, y)\n",
      "    >>> outfile.seek(0) # Only needed here to simulate closing & reopening file\n",
      "    >>> npzfile = np.load(outfile)\n",
      "    >>> npzfile.files\n",
      "    ['arr_1', 'arr_0']\n",
      "    >>> npzfile['arr_0']\n",
      "    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
      "    \n",
      "    Using `savez` with \\**kwds, the arrays are saved with the keyword names.\n",
      "    \n",
      "    >>> outfile = TemporaryFile()\n",
      "    >>> np.savez(outfile, x=x, y=y)\n",
      "    >>> outfile.seek(0)\n",
      "    >>> npzfile = np.load(outfile)\n",
      "    >>> npzfile.files\n",
      "    ['y', 'x']\n",
      "    >>> npzfile['x']\n",
      "    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.savez)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n",
      " 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47\n",
      " 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71\n",
      " 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95\n",
      " 96 97 98 99]\n",
      "[[0 1 2 3 4 5 6 7 8 9]\n",
      " [0 1 2 3 4 5 6 7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "print(array1)\n",
    "print(array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 推荐用这种指定key的方式 默认以npz结尾\n",
    "np.savez('good',array1=array1,array2=array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bak.npy  good.npz  NumpyBase.ipynb  矩阵系列.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "temp = np.load('good.npz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,\n",
       "       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
       "       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,\n",
       "       51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,\n",
       "       68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,\n",
       "       85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp['array1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
       "       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp['array2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 扩展系列 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 默认以npz结尾\n",
    "np.savez('some',array1,array2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bak.npy  good.npz  NumpyBase.ipynb  some.npz  矩阵系列.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.lib.npyio.NpzFile"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = np.load('some.npz')\n",
    "\n",
    "type(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['arr_0', 'arr_1']\n"
     ]
    }
   ],
   "source": [
    "# 知道有那些文件名，也就是对应的key了\n",
    "keys = temp.files\n",
    "\n",
    "print(keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,\n",
       "       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
       "       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,\n",
       "       51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,\n",
       "       68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,\n",
       "       85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过这种方式获取\n",
    "temp[keys[0]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
       "       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp[keys[1]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "看个图就知道它多文件是啥意思了\n",
    "![npy](https://images2018.cnblogs.com/blog/1127869/201807/1127869-20180714145334749-208486178.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.5.合并系列（concatenate、hstack、vstack）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.5.1.`concatenate`\n",
    "\n",
    "`np.concatenate(tuple,axis=0)` 默认是x轴拼接（上下、按照列顺序），`axis=1` => y轴拼接（左右、按照行顺序）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function concatenate in module numpy.core.multiarray:\n",
      "\n",
      "concatenate(...)\n",
      "    concatenate((a1, a2, ...), axis=0, out=None)\n",
      "    \n",
      "    Join a sequence of arrays along an existing axis.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    a1, a2, ... : sequence of array_like\n",
      "        The arrays must have the same shape, except in the dimension\n",
      "        corresponding to `axis` (the first, by default).\n",
      "    axis : int, optional\n",
      "        The axis along which the arrays will be joined.  Default is 0.\n",
      "    out : ndarray, optional\n",
      "        If provided, the destination to place the result. The shape must be\n",
      "        correct, matching that of what concatenate would have returned if no\n",
      "        out argument were specified.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    res : ndarray\n",
      "        The concatenated array.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    ma.concatenate : Concatenate function that preserves input masks.\n",
      "    array_split : Split an array into multiple sub-arrays of equal or\n",
      "                  near-equal size.\n",
      "    split : Split array into a list of multiple sub-arrays of equal size.\n",
      "    hsplit : Split array into multiple sub-arrays horizontally (column wise)\n",
      "    vsplit : Split array into multiple sub-arrays vertically (row wise)\n",
      "    dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).\n",
      "    stack : Stack a sequence of arrays along a new axis.\n",
      "    hstack : Stack arrays in sequence horizontally (column wise)\n",
      "    vstack : Stack arrays in sequence vertically (row wise)\n",
      "    dstack : Stack arrays in sequence depth wise (along third dimension)\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    When one or more of the arrays to be concatenated is a MaskedArray,\n",
      "    this function will return a MaskedArray object instead of an ndarray,\n",
      "    but the input masks are *not* preserved. In cases where a MaskedArray\n",
      "    is expected as input, use the ma.concatenate function from the masked\n",
      "    array module instead.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> a = np.array([[1, 2], [3, 4]])\n",
      "    >>> b = np.array([[5, 6]])\n",
      "    >>> np.concatenate((a, b), axis=0)\n",
      "    array([[1, 2],\n",
      "           [3, 4],\n",
      "           [5, 6]])\n",
      "    >>> np.concatenate((a, b.T), axis=1)\n",
      "    array([[1, 2, 5],\n",
      "           [3, 4, 6]])\n",
      "    \n",
      "    This function will not preserve masking of MaskedArray inputs.\n",
      "    \n",
      "    >>> a = np.ma.arange(3)\n",
      "    >>> a[1] = np.ma.masked\n",
      "    >>> b = np.arange(2, 5)\n",
      "    >>> a\n",
      "    masked_array(data = [0 -- 2],\n",
      "                 mask = [False  True False],\n",
      "           fill_value = 999999)\n",
      "    >>> b\n",
      "    array([2, 3, 4])\n",
      "    >>> np.concatenate([a, b])\n",
      "    masked_array(data = [0 1 2 2 3 4],\n",
      "                 mask = False,\n",
      "           fill_value = 999999)\n",
      "    >>> np.ma.concatenate([a, b])\n",
      "    masked_array(data = [0 -- 2 2 3 4],\n",
      "                 mask = [False  True False False False False],\n",
      "           fill_value = 999999)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.concatenate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 6 6]\n",
      " [3 7 3]]\n"
     ]
    }
   ],
   "source": [
    "A = np.random.randint(10,size=(2,3))\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 6, 6],\n",
       "       [3, 7, 3],\n",
       "       [3, 6, 6],\n",
       "       [3, 7, 3]])"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认是上下（x轴）拼接，第一个参数是元组\n",
    "np.concatenate((A,A))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 6, 6, 3, 6, 6],\n",
       "       [3, 7, 3, 3, 7, 3]])"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 左右（沿y轴）拼接\n",
    "np.concatenate((A,A),axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.5.2.hstack and vstack\n",
    "\n",
    "注意一点：concatenate只能处理一个维度的，如果维度不同可以使用容错性更强的`vstack`（垂直拼接）和`hstack`（水平拼接）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 6 6]\n",
      " [3 7 3]]\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'new_test_array' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-127-1d57e04ff24b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_test_array\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnew_test_array\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# 只能处理一个维度的\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'new_test_array' is not defined"
     ]
    }
   ],
   "source": [
    "print(A)\n",
    "print(new_test_array)\n",
    "\n",
    "np.concatenate((A,new_test_array)) # 只能处理一个维度的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function hstack in module numpy.core.shape_base:\n",
      "\n",
      "hstack(tup)\n",
      "    Stack arrays in sequence horizontally (column wise).\n",
      "    \n",
      "    This is equivalent to concatenation along the second axis, except for 1-D\n",
      "    arrays where it concatenates along the first axis. Rebuilds arrays divided\n",
      "    by `hsplit`.\n",
      "    \n",
      "    This function makes most sense for arrays with up to 3 dimensions. For\n",
      "    instance, for pixel-data with a height (first axis), width (second axis),\n",
      "    and r/g/b channels (third axis). The functions `concatenate`, `stack` and\n",
      "    `block` provide more general stacking and concatenation operations.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    tup : sequence of ndarrays\n",
      "        The arrays must have the same shape along all but the second axis,\n",
      "        except 1-D arrays which can be any length.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    stacked : ndarray\n",
      "        The array formed by stacking the given arrays.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    stack : Join a sequence of arrays along a new axis.\n",
      "    vstack : Stack arrays in sequence vertically (row wise).\n",
      "    dstack : Stack arrays in sequence depth wise (along third axis).\n",
      "    concatenate : Join a sequence of arrays along an existing axis.\n",
      "    hsplit : Split array along second axis.\n",
      "    block : Assemble arrays from blocks.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> a = np.array((1,2,3))\n",
      "    >>> b = np.array((2,3,4))\n",
      "    >>> np.hstack((a,b))\n",
      "    array([1, 2, 3, 2, 3, 4])\n",
      "    >>> a = np.array([[1],[2],[3]])\n",
      "    >>> b = np.array([[2],[3],[4]])\n",
      "    >>> np.hstack((a,b))\n",
      "    array([[1, 2],\n",
      "           [2, 3],\n",
      "           [3, 4]])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.hstack)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 6 6]\n",
      " [3 7 3]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[3, 6, 6, 3, 6, 6],\n",
       "       [3, 7, 3, 3, 7, 3]])"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(A)\n",
    "\n",
    "np.hstack((A,A))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 6, 6],\n",
       "       [3, 7, 3],\n",
       "       [3, 6, 6],\n",
       "       [3, 7, 3]])"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack((A,A))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'new_test_array' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-131-2b6aab3c90b4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_test_array\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhstack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnew_test_array\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'new_test_array' is not defined"
     ]
    }
   ],
   "source": [
    "print(new_test_array)\n",
    "\n",
    "np.hstack((A,new_test_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'new_test_array' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-132-97df5d70dcf5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# 元素不够也是一样报错的\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvstack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnew_test_array\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'new_test_array' is not defined"
     ]
    }
   ],
   "source": [
    "# 元素不够也是一样报错的\n",
    "np.vstack((A,new_test_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function vstack in module numpy.core.shape_base:\n",
      "\n",
      "vstack(tup)\n",
      "    Stack arrays in sequence vertically (row wise).\n",
      "    \n",
      "    This is equivalent to concatenation along the first axis after 1-D arrays\n",
      "    of shape `(N,)` have been reshaped to `(1,N)`. Rebuilds arrays divided by\n",
      "    `vsplit`.\n",
      "    \n",
      "    This function makes most sense for arrays with up to 3 dimensions. For\n",
      "    instance, for pixel-data with a height (first axis), width (second axis),\n",
      "    and r/g/b channels (third axis). The functions `concatenate`, `stack` and\n",
      "    `block` provide more general stacking and concatenation operations.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    tup : sequence of ndarrays\n",
      "        The arrays must have the same shape along all but the first axis.\n",
      "        1-D arrays must have the same length.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    stacked : ndarray\n",
      "        The array formed by stacking the given arrays, will be at least 2-D.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    stack : Join a sequence of arrays along a new axis.\n",
      "    hstack : Stack arrays in sequence horizontally (column wise).\n",
      "    dstack : Stack arrays in sequence depth wise (along third dimension).\n",
      "    concatenate : Join a sequence of arrays along an existing axis.\n",
      "    vsplit : Split array into a list of multiple sub-arrays vertically.\n",
      "    block : Assemble arrays from blocks.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> a = np.array([1, 2, 3])\n",
      "    >>> b = np.array([2, 3, 4])\n",
      "    >>> np.vstack((a,b))\n",
      "    array([[1, 2, 3],\n",
      "           [2, 3, 4]])\n",
      "    \n",
      "    >>> a = np.array([[1], [2], [3]])\n",
      "    >>> b = np.array([[2], [3], [4]])\n",
      "    >>> np.vstack((a,b))\n",
      "    array([[1],\n",
      "           [2],\n",
      "           [3],\n",
      "           [2],\n",
      "           [3],\n",
      "           [4]])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.vstack)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.6.切割系列（split、hsplit、vsplit）\n",
    "\n",
    "**按行切割** `np.split(test_array,[index])` 简化：`np.vsplit(test_array,[index])`\n",
    "\n",
    "**按列切割** `np.split(test_array,[index],axis=1)` 简化：`np.hsplit(test_array,[index])`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[8 7 0 7 8 6 3 0 1 2]\n"
     ]
    }
   ],
   "source": [
    "A = np.random.randint(10,size=10) # np.arange(10)\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[8 7]\n",
      "[0 7 8 6 3 0 1 2]\n"
     ]
    }
   ],
   "source": [
    "a,b = np.split(A,[2])\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[8 7]\n",
      "[0 7]\n",
      "[8 6 3 0 1 2]\n"
     ]
    }
   ],
   "source": [
    "# 索引2、4分割\n",
    "a,b,c = np.split(A,[2,4])\n",
    "\n",
    "print(a)\n",
    "print(b)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 多维系列 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 6 3 2 3]\n",
      " [2 1 9 8 2]\n",
      " [1 7 9 6 3]\n",
      " [9 0 2 4 2]]\n"
     ]
    }
   ],
   "source": [
    "test_array = np.random.randint(10,size=(4,5))\n",
    "\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 6 3 2 3]]\n",
      "[[2 1 9 8 2]\n",
      " [1 7 9 6 3]\n",
      " [9 0 2 4 2]]\n"
     ]
    }
   ],
   "source": [
    "# 按行切割\n",
    "a,b = np.split(test_array,[1])\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 6 3 2 3]]\n",
      "[[2 1 9 8 2]\n",
      " [1 7 9 6 3]\n",
      " [9 0 2 4 2]]\n"
     ]
    }
   ],
   "source": [
    "# 简化写法\n",
    "a,b = np.vsplit(test_array,[1])\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2]\n",
      " [2]\n",
      " [1]\n",
      " [9]]\n",
      "[[6 3 2 3]\n",
      " [1 9 8 2]\n",
      " [7 9 6 3]\n",
      " [0 2 4 2]]\n"
     ]
    }
   ],
   "source": [
    "# 按列切割\n",
    "a,b = np.split(test_array,[1],axis=1)\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2]\n",
      " [2]\n",
      " [1]\n",
      " [9]]\n",
      "[[6 3 2 3]\n",
      " [1 9 8 2]\n",
      " [7 9 6 3]\n",
      " [0 2 4 2]]\n"
     ]
    }
   ],
   "source": [
    "# 简化写法\n",
    "a,b = np.hsplit(test_array,[1])\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function split in module numpy.lib.shape_base:\n",
      "\n",
      "split(ary, indices_or_sections, axis=0)\n",
      "    Split an array into multiple sub-arrays.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    ary : ndarray\n",
      "        Array to be divided into sub-arrays.\n",
      "    indices_or_sections : int or 1-D array\n",
      "        If `indices_or_sections` is an integer, N, the array will be divided\n",
      "        into N equal arrays along `axis`.  If such a split is not possible,\n",
      "        an error is raised.\n",
      "    \n",
      "        If `indices_or_sections` is a 1-D array of sorted integers, the entries\n",
      "        indicate where along `axis` the array is split.  For example,\n",
      "        ``[2, 3]`` would, for ``axis=0``, result in\n",
      "    \n",
      "          - ary[:2]\n",
      "          - ary[2:3]\n",
      "          - ary[3:]\n",
      "    \n",
      "        If an index exceeds the dimension of the array along `axis`,\n",
      "        an empty sub-array is returned correspondingly.\n",
      "    axis : int, optional\n",
      "        The axis along which to split, default is 0.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    sub-arrays : list of ndarrays\n",
      "        A list of sub-arrays.\n",
      "    \n",
      "    Raises\n",
      "    ------\n",
      "    ValueError\n",
      "        If `indices_or_sections` is given as an integer, but\n",
      "        a split does not result in equal division.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    array_split : Split an array into multiple sub-arrays of equal or\n",
      "                  near-equal size.  Does not raise an exception if\n",
      "                  an equal division cannot be made.\n",
      "    hsplit : Split array into multiple sub-arrays horizontally (column-wise).\n",
      "    vsplit : Split array into multiple sub-arrays vertically (row wise).\n",
      "    dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).\n",
      "    concatenate : Join a sequence of arrays along an existing axis.\n",
      "    stack : Join a sequence of arrays along a new axis.\n",
      "    hstack : Stack arrays in sequence horizontally (column wise).\n",
      "    vstack : Stack arrays in sequence vertically (row wise).\n",
      "    dstack : Stack arrays in sequence depth wise (along third dimension).\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> x = np.arange(9.0)\n",
      "    >>> np.split(x, 3)\n",
      "    [array([ 0.,  1.,  2.]), array([ 3.,  4.,  5.]), array([ 6.,  7.,  8.])]\n",
      "    \n",
      "    >>> x = np.arange(8.0)\n",
      "    >>> np.split(x, [3, 5, 6, 10])\n",
      "    [array([ 0.,  1.,  2.]),\n",
      "     array([ 3.,  4.]),\n",
      "     array([ 5.]),\n",
      "     array([ 6.,  7.]),\n",
      "     array([], dtype=float64)]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.split)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.7.扩展系列\n",
    "\n",
    "#### 2.7.1.`np.copy`\n",
    "\n",
    "我们先来看看为什么要用copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0, 1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "test_list = list(range(10))\n",
    "print(test_list)\n",
    "\n",
    "# 在Python中切片是不改变原列表的\n",
    "new_test_list = test_list[:5]\n",
    "print(test_list)\n",
    "print(new_test_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[22, 1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "# 修改切片出来的列表不影响原列表\n",
    "new_test_list[0] = 22\n",
    "print(test_list)\n",
    "print(new_test_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 5 1 0 1]\n",
      " [2 9 5 8 7]\n",
      " [0 7 0 6 2]]\n",
      "[[4 5]\n",
      " [2 9]]\n",
      "[[4 5 1 0 1]\n",
      " [2 9 5 8 7]\n",
      " [0 7 0 6 2]]\n"
     ]
    }
   ],
   "source": [
    "# 再看看Numpy的数组\n",
    "test_array = np.random.randint(10,size=(3,5))\n",
    "print(test_array)\n",
    "\n",
    "new_test_array = test_array[:2,:2]\n",
    "print(new_test_array)\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[22  5]\n",
      " [ 2  9]]\n",
      "[[22  5  1  0  1]\n",
      " [ 2  9  5  8  7]\n",
      " [ 0  7  0  6  2]]\n"
     ]
    }
   ],
   "source": [
    "# Numpy只要效率，所以不是真的给你切出新数组\n",
    "new_test_array[0,0]=22\n",
    "\n",
    "print(new_test_array)\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### Copy登场 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[22  5  1  0  1]\n",
      " [ 2  9  5  8  7]\n",
      " [ 0  7  0  6  2]]\n",
      "[[22  5]\n",
      " [ 2  9]]\n"
     ]
    }
   ],
   "source": [
    "print(test_array)\n",
    "\n",
    "temp = test_array.copy()\n",
    "new_test_array = temp[:2,:2]\n",
    "\n",
    "print(new_test_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[6 5]\n",
      " [2 9]]\n",
      "[[22  5  1  0  1]\n",
      " [ 2  9  5  8  7]\n",
      " [ 0  7  0  6  2]]\n"
     ]
    }
   ],
   "source": [
    "# 验证一下是不是真的copy，的确是真copy\n",
    "new_test_array[0,0] = 6\n",
    "\n",
    "print(new_test_array)\n",
    "print(test_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.7.2.效率测试（time、timeit）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 15.1 ms, sys: 11.9 ms, total: 27 ms\n",
      "Wall time: 26.8 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "A = list(range(1000000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 11.2 ms, sys: 7.34 ms, total: 18.6 ms\n",
      "Wall time: 17.3 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "A = np.arange(1000000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.52 µs ± 651 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
      "1.63 µs ± 52.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n"
     ]
    }
   ],
   "source": [
    "# 之前讲sum、max、min提供两种写法，这次测试下\n",
    "big_array = np.random.randint(10,size=(3,5))\n",
    "%timeit np.sum(big_array[0])\n",
    "%timeit sum(big_array[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.7.3.统计相关（平均值、中位数、百分位、方差、标准差等）\n",
    "\n",
    "后面有机会会说说数学里面的统计学，到时候还会再说的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n"
     ]
    }
   ],
   "source": [
    "A = np.arange(1,7).reshape(3,-1)\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵元素的乘积\n",
    "np.prod(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 平均值\n",
    "np.mean(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 中位数\n",
    "# 把所有观察值高低排序后找出正中间的一个作为中位数\n",
    "# 如果观察值有偶数个，通常取最中间的两个数值的平均数作为中位数\n",
    "np.median(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.25"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 百分数，在这些元素中百分之25的元素都是<=xxx的\n",
    "np.percentile(A,q=25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\n",
      "2.25\n",
      "3.5\n",
      "4.75\n",
      "6.0\n"
     ]
    }
   ],
   "source": [
    "# 实际场景：样本分布情况\n",
    "for i in [0,25,50,75,100]:\n",
    "    print(np.percentile(A,q=i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.9166666666666665"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方差\n",
    "np.var(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.707825127659933"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标准差\n",
    "np.std(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 变化开始 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 应用场景：正态分布验证\n",
    "# eg:均值为0，标准差为1\n",
    "test = np.random.normal(0,1, size=(100,50))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.004244947279570449"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 基本上等于0\n",
    "np.mean(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9957424470098744"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 基本上为1\n",
    "np.std(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 灵活运用 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3  4  5]\n",
      " [ 6  7  8  9 10]\n",
      " [11 12 13 14 15]]\n"
     ]
    }
   ],
   "source": [
    "A = np.arange(1,16).reshape(3,-1)\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 有一个小于4就返回True\n",
    "np.any(A < 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有的都小于4才返回True\n",
    "np.all(A < 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵进行运算，都是针对所有元素的\n",
    "A % 2 == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看有几个偶数\n",
    "np.sum(A % 2 ==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3, 2])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 每一行有几个\n",
    "np.sum(A%2==0, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 1, 2, 1])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 每一列\n",
    "np.sum(A%2==0, axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.7.4.索引相关扩展\n",
    "\n",
    "主要是argxxx获得索引\n",
    "\n",
    "`argmax` 获取最大值的索引\n",
    "\n",
    "`argmin` 获取最小值的索引\n",
    "\n",
    "`argsort`获取排序后的索引\n",
    "\n",
    "`argpartition`以对应值为分割的索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 5 7 8]\n",
      " [6 7 6 3]\n",
      " [7 6 7 1]]\n"
     ]
    }
   ],
   "source": [
    "A = np.random.randint(10,size=(3,4))\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取最大值的索引\n",
    "np.argmax(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取最小值的索引\n",
    "np.argmin(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 分割线 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 5 7 8]\n",
      " [7 6 7 1]\n",
      " [6 7 6 3]]\n"
     ]
    }
   ],
   "source": [
    "# 先打乱一下\n",
    "np.random.shuffle(A)\n",
    "\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 7, 8],\n",
       "       [1, 6, 7, 7],\n",
       "       [3, 6, 6, 7]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对于矩阵，是每一行排序\n",
    "np.sort(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 7, 8],\n",
       "       [7, 6, 7, 1],\n",
       "       [6, 7, 6, 3]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 注意一点：用np.sort(A)，A本身没变化，想要变化使用A.sort\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3],\n",
       "       [3, 1, 0, 2],\n",
       "       [3, 0, 2, 1]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回原数组对应索引\n",
    "np.argsort(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "################### 分割线 ########################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 7 6 3 8 0 3 7 5 8]\n"
     ]
    }
   ],
   "source": [
    "# 先熟悉一下这个函数\n",
    "A = np.random.randint(10,size=10)\n",
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 3, 3, 5, 5, 6, 7, 7, 8, 8])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以4为分割，比4大的在前面，比4小的在后面（不排序）\n",
    "np.partition(A,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 3, 6, 8, 0, 2, 1, 7, 4, 9])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回对应索引\n",
    "np.argpartition(A,4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "还有什么补充以后就添加在这"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
